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

56 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-06-26 01:39:02 +08:00
import dotenv from 'dotenv';
dotenv.config();
2021-06-06 18:30:37 +08:00
import Koa from 'koa';
2021-06-26 01:39:02 +08:00
import logger from 'koa-logger';
2021-06-19 22:53:34 +08:00
import mount from 'koa-mount';
import Router from 'koa-router';
import { Provider } from 'oidc-provider';
2021-06-26 01:39:02 +08:00
import postgresAdapter from './oidc/adapter';
2021-06-19 22:53:34 +08:00
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`, {
2021-06-26 01:39:02 +08:00
adapter: postgresAdapter,
renderError: (ctx, out, error) => {
console.log(error);
},
2021-06-21 22:44:37 +08:00
cookies: {
// V2: Rotate this when necessary
// https://github.com/panva/node-oidc-provider/blob/main/docs/README.md#cookieskeys
keys: ['LOGTOSEKRIT1'],
2021-06-19 22:53:34 +08:00
},
clients: [
{
client_id: 'foo',
redirect_uris: ['http://localhost:3000/callback'],
2021-06-21 22:44:37 +08:00
grant_types: ['authorization_code', 'refresh_token'],
token_endpoint_auth_method: 'none',
2021-06-19 22:53:34 +08:00
},
],
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';
});
2021-06-26 01:39:02 +08:00
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
app.use(logger()).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}`);
});