forked from appvia/mock-oidc-user-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
55 lines (46 loc) · 1.3 KB
/
server.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
/* eslint-disable no-console */
const assert = require('assert');
const camelCase = require('camelcase');
const Provider = require('oidc-provider');
const port = process.env.PORT || 3000;
const config = ['CLIENT_ID', 'CLIENT_SECRET', 'CLIENT_REDIRECT_URI', 'CLIENT_LOGOUT_REDIRECT_URI'].reduce((acc, v) => {
assert(process.env[v], `${v} config missing`);
acc[camelCase(v)] = process.env[v];
return acc;
}, {});
const oidcConfig = {
features: {
devInteractions: true,
discovery: true,
registration: false,
revocation: true,
sessionManagement: false
},
format: {
default: 'jwt',
AccessToken: 'jwt',
RefreshToken: 'jwt'
}
};
const oidc = new Provider(`http://localhost:${port}`, oidcConfig);
const clients = [
{
client_id: config.clientId,
client_secret: config.clientSecret,
redirect_uris: [config.clientRedirectUri],
post_logout_redirect_uris: [config.clientLogoutRedirectUri]
}
];
let server;
(async () => {
await oidc.initialize({ clients });
server = oidc.listen(port, () => {
console.log(
`mock-oidc-user-server listening on port ${port}, check http://localhost:${port}/.well-known/openid-configuration`
);
});
})().catch(err => {
if (server && server.listening) server.close();
console.error(err);
process.exitCode = 1;
});