-
Notifications
You must be signed in to change notification settings - Fork 375
/
Copy pathoidc-provider.js
105 lines (98 loc) · 2.54 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { Provider, interactionPolicy } from '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',
redirect_uris: ['http://127.0.0.1:3000', 'http://localhost:3000'],
token_endpoint_auth_method: 'none',
grant_types: ['authorization_code', 'refresh_token']
},
{
client_id: 'multi-client-1',
redirect_uris: [
'http://127.0.0.1:3000/multiple_clients.html',
'http://localhost:3000/multiple_clients.html'
],
token_endpoint_auth_method: 'none',
grant_types: ['authorization_code', 'refresh_token']
},
{
client_id: 'multi-client-2',
redirect_uris: [
'http://127.0.0.1:3000/multiple_clients.html',
'http://localhost:3000/multiple_clients.html'
],
token_endpoint_auth_method: 'none',
grant_types: ['authorization_code', 'refresh_token']
},
{
client_id: 'multi-client-3',
redirect_uris: [
'http://127.0.0.1:3000/multiple_clients.html',
'http://localhost:3000/multiple_clients.html'
],
token_endpoint_auth_method: 'none',
grant_types: ['authorization_code', 'refresh_token']
}
],
claims: {
org_id: null
},
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
},
claimsParameter: {
enabled: true
}
},
rotateRefreshToken: true,
interactions: {
policy
},
findAccount(ctx, id) {
return {
accountId: id,
claims(use, scope, claims) {
return {
sub: id,
...(claims?.org_id ? { org_id: claims.org_id.values[0] } : null)
};
}
};
}
};
export function createApp(opts) {
const issuer = `http://127.0.0.1:${opts.port || 3000}/`;
const provider = new Provider(issuer, config);
provider.use(async (ctx, next) => {
await next();
if (ctx.oidc?.route === 'end_session_success') {
ctx.redirect('http://127.0.0.1:3000');
}
});
return provider.app;
}