Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/fastify/fastify-oauth2 in…
Browse files Browse the repository at this point in the history
…to next
  • Loading branch information
gurgunday committed Apr 25, 2024
2 parents cf9dc28 + 9de18d6 commit f3d6857
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ function fastifyOauth2 (fastify, options, next) {
if (options.discovery && options.credentials.auth) {
return next(new Error('when options.discovery.issuer is configured, credentials.auth should not be used'))
}
if (!options.discovery && !options.credentials.auth) {
return next(new Error('options.discovery.issuer or credentials.auth have to be given'))
}
if (!fastify.hasReplyDecorator('cookie')) {
fastify.register(require('@fastify/cookie'))
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fastify/oauth2",
"version": "7.8.0",
"version": "7.8.1",
"description": "Perform login using oauth2 protocol",
"main": "index.js",
"type": "commonjs",
Expand Down
20 changes: 20 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,26 @@ t.test('credentials.auth should not be provided when discovery is used', t => {
})
})

t.test('not providing options.discovery.issuer and credentials.auth', t => {
t.plan(1)

const fastify = createFastify({ logger: { level: 'silent' } })

fastify.register(fastifyOauth2, {
name: 'the-name',
credentials: {
client: {
id: 'my-client-id',
secret: 'my-secret'
}
},
callbackUri: '/callback'
})
.ready(err => {
t.strictSame(err.message, 'options.discovery.issuer or credentials.auth have to be given')
})
})

t.test('options.schema', t => {
const fastify = createFastify({ logger: { level: 'silent' }, exposeHeadRoutes: false })

Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ declare namespace fastifyOauth2 {
/** Parameter name used to send the client id. Default to client_id. */
idParamName?: string | undefined;
};
auth: ProviderConfiguration;
auth?: ProviderConfiguration;
/**
* Used to set global options to the internal http library (wreck).
* All options except baseUrl are allowed
Expand Down
2 changes: 1 addition & 1 deletion types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ expectType<string[]>(tags);
expectType<Credentials>(credentials);

// Ensure duplicayed simple-oauth2 are compatible with simple-oauth2
expectAssignable<ModuleOptions<string>>(credentials);
expectAssignable<ModuleOptions<string>>({auth: {tokenHost: ''}, ...credentials });
expectAssignable<ModuleOptions["auth"]>(auth);
// Ensure published types of simple-oauth2 are accepted
expectAssignable<Credentials>(simpleOauth2Options);
Expand Down

0 comments on commit f3d6857

Please sign in to comment.