mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
feat: redirect to configured sign in URL
This commit is contained in:
parent
4f616696e2
commit
21e9d23b33
4 changed files with 28 additions and 6 deletions
3
packages/core/src/consts.ts
Normal file
3
packages/core/src/consts.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
import { assertEnv } from './utils';
|
||||
|
||||
export const signInRoute = assertEnv('SIGN_IN_ROUTE');
|
|
@ -7,6 +7,7 @@ import postgresAdapter from '../oidc/adapter';
|
|||
import { fromKeyLike } from 'jose/jwk/from_key_like';
|
||||
import { getEnv } from '../utils';
|
||||
import { findUserById } from '../queries/user';
|
||||
import { signInRoute } from '../consts';
|
||||
|
||||
export default async function initOidc(app: Koa, port: number): Promise<void> {
|
||||
const privateKey = crypto.createPrivateKey(
|
||||
|
@ -34,8 +35,15 @@ export default async function initOidc(app: Koa, port: number): Promise<void> {
|
|||
token_endpoint_auth_method: 'none',
|
||||
},
|
||||
],
|
||||
features: { revocation: { enabled: true }, introspection: { enabled: true } },
|
||||
clientBasedCORS: (ctx, origin) => {
|
||||
features: {
|
||||
revocation: { enabled: true },
|
||||
introspection: { enabled: true },
|
||||
devInteractions: { enabled: false },
|
||||
},
|
||||
interactions: {
|
||||
url: (_, interaction) => `${signInRoute}?uid=${interaction.uid}`,
|
||||
},
|
||||
clientBasedCORS: (_, origin) => {
|
||||
console.log('origin', origin);
|
||||
return origin.startsWith('http://localhost:3000');
|
||||
},
|
||||
|
@ -44,8 +52,11 @@ export default async function initOidc(app: Koa, port: number): Promise<void> {
|
|||
|
||||
return {
|
||||
accountId: sub,
|
||||
claims: async (use, scope, claims) => {
|
||||
console.log('claims', use, scope, claims);
|
||||
claims: async (use, scope, claims, rejected) => {
|
||||
console.log('use:', use);
|
||||
console.log('scope:', scope);
|
||||
console.log('claims:', claims);
|
||||
console.log('rejected:', rejected);
|
||||
return { sub };
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import Koa from 'koa';
|
||||
import Router from 'koa-router';
|
||||
import { signInRoute } from '../consts';
|
||||
|
||||
const router = new Router();
|
||||
|
||||
router.get('/callback', (ctx) => {
|
||||
ctx.body = 'A callback';
|
||||
router.get(signInRoute, (ctx) => {
|
||||
ctx.body = 'Signing in';
|
||||
});
|
||||
|
||||
export default function initRouter(app: Koa): void {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import assert from 'assert';
|
||||
|
||||
export type Optional<T> = T | undefined;
|
||||
export type Falsy = 0 | undefined | null | false | '';
|
||||
|
||||
|
@ -5,3 +7,8 @@ export const conditional = <T>(value: T | Falsy): Optional<T> => (value ? value
|
|||
export const conditionalString = (value: string | Falsy): string => (value ? value : '');
|
||||
|
||||
export const getEnv = (key: string, fallback = ''): string => process.env[key] ?? fallback;
|
||||
export const assertEnv = (key: string): string => {
|
||||
const value = process.env[key];
|
||||
assert(value, `env variable ${key} not found`);
|
||||
return value;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue