-
Notifications
You must be signed in to change notification settings - Fork 390
/
oidc-provider.js
66 lines (59 loc) · 1.64 KB
/
oidc-provider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const { Provider, interactionPolicy } = require('oidc-provider');
const { base, Prompt, Check } = interactionPolicy;
const policy = base();
policy.add(
new Prompt(
{ name: 'noop', requestable: false },
new Check('foo', 'bar', (ctx) => {
if (ctx.query?.scope?.includes('offline_access')) {
ctx.oidc.params.scope = `${ctx.oidc.params.scope} offline_access`;
}
return Check.NO_NEED_TO_PROMPT;
})
),
0
);
const config = {
clients: [
{
client_id: 'testing',
client_secret: 'testing',
redirect_uris: [
'https://localhost:3000/api/auth/callback',
'https://localhost:3000/api/page-router-auth/callback',
'https://localhost:3000/api/edge-auth/callback'
],
post_logout_redirect_uris: ['https://localhost:3000', 'https://localhost:3000/page-router'],
token_endpoint_auth_method: 'client_secret_post',
grant_types: ['authorization_code', 'refresh_token']
}
],
routes: {
authorization: '/authorize', // lgtm [js/hardcoded-credentials]
token: '/oauth/token',
end_session: '/v2/logout'
},
scopes: ['openid', 'offline_access'],
clientBasedCORS(ctx, origin, client) {
return true;
},
features: {
webMessageResponseMode: {
enabled: true
}
},
interactions: {
policy
}
};
module.exports = function createProvider(opts) {
const issuer = `https://localhost:${opts.port || 3000}/oidc/`;
const provider = new Provider(issuer, config);
provider.use(async (ctx, next) => {
await next();
if (ctx.oidc?.route === 'end_session_success') {
ctx.redirect('https://localhost:3000');
}
});
return provider;
};