forked from appvia/mock-oidc-user-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
48 lines (40 loc) · 1.2 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
const assert = require('assert')
const camelCase = require('camelcase')
const Provider = require('oidc-provider')
const host = process.env.HOST || 'localhost'
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 = {
claims: {
email: ['email'],
profile: ['name', 'preferred_username']
},
clients: [{
client_id: config.clientId,
client_secret: config.clientSecret,
redirect_uris: [config.clientRedirectUri],
post_logout_redirect_uris: [config.clientLogoutRedirectUri]
}],
async findAccount (ctx, id) {
return {
accountId: id,
async claims (use, scope) {
return {
sub: id,
email: 'test@test.ch',
name: 'test',
preferred_username: 'Test'
}
}
}
}
}
const oidc = new Provider(`http://${host}:${port}`, oidcConfig)
oidc.callback()
oidc.listen(port, () => {
console.log(`oidc-provider listening on port ${port}, check http://localhost:${port}/.well-known/openid-configuration`)
})