Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add scope to KeycloakOptions (#3) #4

Merged
merged 1 commit into from
May 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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