Skip to content

Commit

Permalink
Merge pull request #4 from yubinTW/scope
Browse files Browse the repository at this point in the history
add scope to KeycloakOptions
  • Loading branch information
yubinTW authored May 22, 2022
2 parents fa520fa + acc20a4 commit 5e1a11d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ server.register(keycloak, opts)

- `clientSecret` client secret (required)

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

- `logoutEndpoint` route path of doing logout (optional, defaults to `/logout`)

- `excludedPatterns` string array for non-authorized urls (optional, support `?`, `*` and `**` wildcards)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fastify-keycloak-adapter",
"author": "Yubin, Hsu",
"version": "0.5.1",
"version": "0.6.0",
"main": "dist/keycloak",
"types": "dist/keycloak",
"keywords": [
Expand All @@ -25,7 +25,7 @@
"scripts": {
"build": "tsc",
"test": "jest --coverage --runInBand --detectOpenHandles",
"fix-prettier": "prettier --write \"./{src,test}/**/*.ts\""
"fix-prettier": "prettier --write \"./src/**/*.ts\""
},
"dependencies": {
"@fastify/cookie": "^6.0.0",
Expand Down
4 changes: 3 additions & 1 deletion src/keycloak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ export type KeycloakOptions = {
clientSecret?: string
logoutEndpoint?: string
excludedPatterns?: Array<string>
scope?: Array<string>
userPayloadMapper?: (userPayload: UserInfo) => {}
}

export default fastifyPlugin(async (fastify: FastifyInstance, opts: KeycloakOptions) => {
console.log(`opts = ${inspect(opts, false, null)}`)
function getWellKnownConfiguration(url: string) {
return TE.tryCatch(
() => axios.get<WellKnownConfiguration>(url),
Expand Down Expand Up @@ -101,7 +103,7 @@ export default fastifyPlugin(async (fastify: FastifyInstance, opts: KeycloakOpti
authorize_url: config.authorization_endpoint,
access_url: config.token_endpoint,
callback: '/',
scope: ['openid'],
scope: opts.scope ?? ['openid'],
nonce: true
}
})
Expand Down
1 change: 0 additions & 1 deletion src/tests/server.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from 'axios'
import { FastifyInstance } from 'fastify'
import { KeycloakContainer, StartedKeycloakContainer } from 'testcontainers-keycloak'
import { KeycloakOptions } from '../keycloak'
Expand Down

0 comments on commit 5e1a11d

Please sign in to comment.