Skip to content

Commit

Permalink
Merge pull request #19 from yubinTW/feature/callback-option
Browse files Browse the repository at this point in the history
feat(plugin-option): add custom callback option (#18)
  • Loading branch information
yubinTW authored Sep 2, 2022
2 parents d76caf9 + 168a817 commit e6b5fac
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ yarn add fastify-keycloak-adapter
## Fastify Version

- Fastify 4 -> `npm i fastify-keycloak-adapter`
- Fastify 3 -> `npm i [email protected]`
- Fastify 3 -> `npm i [email protected]` (deprecated)

## Usage

Expand Down Expand Up @@ -54,6 +54,8 @@ server.register(keycloak, opts)

- `scope` client scope of keycloak (optional, string[], defaults to `['openid']`)

- `callback` Relative or absolute URL to receive the response data (optional, defaults to `/`)

- `retries` The number of times to retry before failing. (optional, number, defaults to 3)

- `logoutEndpoint` route path of doing logout (optional, defaults to `/logout`)
Expand Down Expand Up @@ -85,7 +87,8 @@ const opts: KeycloakOptions = {
clientId: 'myclient01',
clientSecret: 'myClientSecret',
logoutEndpoint: '/logout',
excludedPatterns: ['/metrics', '/api/todos/**']
excludedPatterns: ['/metrics', '/manifest.json', '/api/todos/**'],
callback: '/hello'
}

server.register(keycloak, opts)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fastify-keycloak-adapter",
"author": "Yubin, Hsu",
"version": "1.5.0",
"version": "1.6.0",
"main": "dist/keycloak",
"keywords": [
"fastify",
Expand Down
3 changes: 2 additions & 1 deletion src/keycloak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const partialOptions = t.partial({
logoutEndpoint: t.readonly(t.string),
excludedPatterns: t.readonly(t.array(t.string)),
scope: t.array(t.readonly(t.string)),
callback: t.readonly(t.string),
disableCookiePlugin: t.readonly(t.boolean),
disableSessionPlugin: t.readonly(t.boolean),
retries: t.readonly(t.number),
Expand Down Expand Up @@ -182,7 +183,7 @@ export default fastifyPlugin(async (fastify: FastifyInstance, opts: KeycloakOpti
oauth: 2,
authorize_url: config.authorization_endpoint,
access_url: config.token_endpoint,
callback: '/',
callback: opts.callback ?? '/',
scope: opts.scope ?? ['openid'],
nonce: true
}
Expand Down

0 comments on commit e6b5fac

Please sign in to comment.