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

feat(core): generate oidc metadata for protected app (#5188)

This commit is contained in:
wangsijie 2024-01-09 11:45:38 +08:00 committed by GitHub
parent 7d35afd30d
commit 0b08da2b46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 3 deletions

View file

@ -110,6 +110,10 @@ describe('application route', () => {
name,
type,
protectedAppMetadata,
oidcClientMetadata: {
redirectUris: [`https://${protectedAppMetadata?.host ?? ''}/callback`],
postLogoutRedirectUris: [`https://${protectedAppMetadata?.host ?? ''}`],
},
});
});

View file

@ -24,7 +24,7 @@ import {
applicationCreateGuard,
applicationPatchGuard,
} from './types.js';
import { buildProtectedAppMetadata } from './utils.js';
import { buildProtectedAppData } from './utils.js';
const includesInternalAdminRole = (roles: Readonly<Array<{ role: Role }>>) =>
roles.some(({ role: { name } }) => name === InternalRole.Admin);
@ -161,7 +161,7 @@ export default function applicationRoutes<T extends AuthedRouter>(
...conditional(
rest.type === ApplicationType.Protected &&
protectedAppMetadata &&
buildProtectedAppMetadata(protectedAppMetadata)
buildProtectedAppData(protectedAppMetadata)
),
...rest,
});

View file

@ -1,10 +1,19 @@
import { defaultProtectedAppPageRules, defaultProtectedAppSessionDuration } from './constants.js';
export const buildProtectedAppMetadata = ({ host, origin }: { host: string; origin: string }) => ({
/**
* Build application data for protected app
* generate default protectedAppMetadata based on host and origin
* generate redirectUris and postLogoutRedirectUris based on host
*/
export const buildProtectedAppData = ({ host, origin }: { host: string; origin: string }) => ({
protectedAppMetadata: {
host,
origin,
sessionDuration: defaultProtectedAppSessionDuration,
pageRules: defaultProtectedAppPageRules,
},
oidcClientMetadata: {
redirectUris: [`https://${host}/callback`],
postLogoutRedirectUris: [`https://${host}`],
},
});