mirror of
https://github.com/logto-io/logto.git
synced 2025-01-20 21:32:31 -05:00
refactor(core): ensure getting the latest data in live preview
This commit is contained in:
parent
db1de6ce4c
commit
11292d4347
3 changed files with 20 additions and 13 deletions
|
@ -7,6 +7,6 @@ describe('oidc provider init', () => {
|
||||||
it('init should not throw', async () => {
|
it('init should not throw', async () => {
|
||||||
const { queries, libraries } = new MockTenant();
|
const { queries, libraries } = new MockTenant();
|
||||||
|
|
||||||
expect(() => initOidc(mockEnvSet, queries, libraries)).not.toThrow();
|
expect(() => initOidc('mock_id', mockEnvSet, queries, libraries)).not.toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,6 +9,7 @@ import i18next from 'i18next';
|
||||||
import Provider, { errors, ResourceServer } from 'oidc-provider';
|
import Provider, { errors, ResourceServer } from 'oidc-provider';
|
||||||
import snakecaseKeys from 'snakecase-keys';
|
import snakecaseKeys from 'snakecase-keys';
|
||||||
|
|
||||||
|
import { wellKnownCache } from '#src/caches/well-known.js';
|
||||||
import type { EnvSet } from '#src/env-set/index.js';
|
import type { EnvSet } from '#src/env-set/index.js';
|
||||||
import { addOidcEventListeners } from '#src/event-listeners/index.js';
|
import { addOidcEventListeners } from '#src/event-listeners/index.js';
|
||||||
import koaAuditLog from '#src/middleware/koa-audit-log.js';
|
import koaAuditLog from '#src/middleware/koa-audit-log.js';
|
||||||
|
@ -25,7 +26,12 @@ import { OIDCExtraParametersKey, InteractionMode } from './type.js';
|
||||||
// Temporarily removed 'EdDSA' since it's not supported by browser yet
|
// Temporarily removed 'EdDSA' since it's not supported by browser yet
|
||||||
const supportedSigningAlgs = Object.freeze(['RS256', 'PS256', 'ES256', 'ES384', 'ES512'] as const);
|
const supportedSigningAlgs = Object.freeze(['RS256', 'PS256', 'ES256', 'ES384', 'ES512'] as const);
|
||||||
|
|
||||||
export default function initOidc(envSet: EnvSet, queries: Queries, libraries: Libraries): Provider {
|
export default function initOidc(
|
||||||
|
tenantId: string,
|
||||||
|
envSet: EnvSet,
|
||||||
|
queries: Queries,
|
||||||
|
libraries: Libraries
|
||||||
|
): Provider {
|
||||||
const {
|
const {
|
||||||
issuer,
|
issuer,
|
||||||
cookieKeys,
|
cookieKeys,
|
||||||
|
@ -140,24 +146,25 @@ export default function initOidc(envSet: EnvSet, queries: Queries, libraries: Li
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
interactions: {
|
interactions: {
|
||||||
url: (ctx, interaction) => {
|
url: async (ctx, interaction) => {
|
||||||
|
const isDemoApp = interaction.params.client_id === demoAppApplicationId;
|
||||||
|
|
||||||
const appendParameters = (path: string) => {
|
const appendParameters = (path: string) => {
|
||||||
// `notification` is for showing a text banner on the homepage
|
// `notification` is for showing a text banner on the homepage
|
||||||
return interaction.params.client_id === demoAppApplicationId
|
return isDemoApp ? path + `?notification=demo_app.notification` : path;
|
||||||
? path + `?notification=demo_app.notification`
|
|
||||||
: path;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (interaction.prompt.name) {
|
switch (interaction.prompt.name) {
|
||||||
case 'login': {
|
case 'login': {
|
||||||
if (
|
// Always fetch the latest sign-in experience config for demo app (live preview)
|
||||||
// Register user experience first
|
if (isDemoApp) {
|
||||||
ctx.oidc.params?.[OIDCExtraParametersKey.InteractionMode] === InteractionMode.signUp
|
await wellKnownCache.invalidate(tenantId, ['sie', 'sie-full']);
|
||||||
) {
|
|
||||||
return appendParameters(routes.signUp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return appendParameters(routes.signIn.credentials);
|
const isSignUp =
|
||||||
|
ctx.oidc.params?.[OIDCExtraParametersKey.InteractionMode] === InteractionMode.signUp;
|
||||||
|
|
||||||
|
return appendParameters(isSignUp ? routes.signUp : routes.signIn.credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'consent': {
|
case 'consent': {
|
||||||
|
|
|
@ -71,7 +71,7 @@ export default class Tenant implements TenantContext {
|
||||||
app.use(koaCompress());
|
app.use(koaCompress());
|
||||||
|
|
||||||
// Mount OIDC
|
// Mount OIDC
|
||||||
const provider = initOidc(envSet, queries, libraries);
|
const provider = initOidc(id, envSet, queries, libraries);
|
||||||
app.use(mount('/oidc', provider.app));
|
app.use(mount('/oidc', provider.app));
|
||||||
|
|
||||||
const tenantContext: TenantContext = {
|
const tenantContext: TenantContext = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue