0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-03 21:48:55 -05:00
logto/packages/core/src/index.ts

45 lines
994 B
TypeScript
Raw Normal View History

2021-06-06 18:30:37 +08:00
import Koa from 'koa';
2021-06-19 22:53:34 +08:00
import mount from 'koa-mount';
import Router from 'koa-router';
import { Provider } from 'oidc-provider';
const router = new Router();
2021-06-06 18:30:37 +08:00
const app = new Koa();
2021-06-19 22:53:34 +08:00
const PORT = 3000;
2021-06-06 18:30:37 +08:00
2021-06-19 22:53:34 +08:00
const oidc = new Provider(`http://localhost:${PORT}/oidc`, {
pkce: {
methods: ['S256'],
required: () => false,
},
clients: [
{
client_id: 'foo',
client_secret: 'bar',
redirect_uris: ['http://localhost:3000/callback'],
grant_types: ['authorization_code'],
},
],
findAccount: (ctx, sub) => {
console.log('finding account');
return {
accountId: sub,
claims: async (use, scope, claims) => {
console.log('claims', use, scope, claims);
return { sub };
},
};
},
2021-06-06 18:30:37 +08:00
});
2021-06-19 22:53:34 +08:00
router.get('/callback', (ctx) => {
ctx.body = 'A callback';
});
app.use(mount('/oidc', oidc.app)).use(router.routes()).use(router.allowedMethods());
2021-06-06 18:30:37 +08:00
app.listen(PORT, () => {
console.log(`App is listening on port ${PORT}`);
});