0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -05:00

refactor(core): support oidc configuration hot replace (#4590)

This commit is contained in:
Charles Zhao 2023-10-09 05:05:07 -05:00 committed by GitHub
parent f27a3ee2a7
commit c913406926
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -42,7 +42,6 @@ export default function initOidc(
queries: Queries,
libraries: Libraries
): Provider {
const { issuer, cookieKeys, privateJwks, jwkSigningAlg } = envSet.oidc;
const {
resources: { findResourceByIndicator, findDefaultResource },
users: { findUserById },
@ -58,7 +57,9 @@ export default function initOidc(
signed: true,
} as const);
const oidc = new Provider(issuer, {
// Do NOT deconstruct variables from `envSet` earlier, since we might reload `envSet` on the fly,
// and keeping the reference of the `envSet` object helps dynamically update oidc provider configs.
const oidc = new Provider(envSet.oidc.issuer, {
adapter: postgresAdapter.bind(null, envSet, queries),
// Align the error response regardless of the request format. It will be `application/json` by default.
// Rendering different error response based on the request format is okay, but it brought more trouble
@ -71,12 +72,12 @@ export default function initOidc(
ctx.body = out;
},
cookies: {
keys: cookieKeys,
keys: envSet.oidc.cookieKeys,
long: cookieConfig,
short: cookieConfig,
},
jwks: {
keys: privateJwks,
keys: envSet.oidc.privateJwks,
},
enabledJWA: {
authorizationSigningAlgValues: [...supportedSigningAlgs],
@ -126,7 +127,7 @@ export default function initOidc(
accessTokenFormat: 'jwt',
accessTokenTTL,
jwt: {
sign: { alg: jwkSigningAlg },
sign: { alg: envSet.oidc.jwkSigningAlg },
},
scope: '',
} satisfies ResourceServer;