@muze-nl/metro-oidc 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser-dev.js +45 -2
- package/dist/browser-dev.js.map +3 -3
- package/dist/browser.js +1 -1
- package/dist/browser.js.map +4 -4
- package/package.json +1 -1
- package/src/oidc.discovery.mjs +1 -1
- package/src/oidc.store.mjs +18 -0
- package/src/oidcmw.mjs +23 -8
package/src/oidcmw.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import oauth2mw from '@muze-nl/metro-oauth2'
|
|
|
3
3
|
import { assert, Required, Optional, validURL, instanceOf } from '@muze-nl/assert'
|
|
4
4
|
import discover from './oidc.discovery.mjs'
|
|
5
5
|
import register from './oidc.register.mjs'
|
|
6
|
+
import oidcStore from './oidc.store.mjs'
|
|
6
7
|
|
|
7
8
|
export default function oidcmw(options={}) {
|
|
8
9
|
|
|
@@ -13,13 +14,23 @@ export default function oidcmw(options={}) {
|
|
|
13
14
|
|
|
14
15
|
options = Object.assign({}, defaultOptions, options)
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
assert(options, {
|
|
18
|
+
client: Required(instanceOf(metro.client().constructor)), // required because it is set in defaultOptions
|
|
19
|
+
client_info: Required(),
|
|
20
|
+
issuer: Required(validURL),
|
|
21
|
+
oauth2: Optional({}),
|
|
22
|
+
openid_configuration: Optional()
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
if (!options.store) {
|
|
26
|
+
options.store = oidcStore(options.issuer)
|
|
27
|
+
}
|
|
28
|
+
if (!options.openid_configuration && options.store.has('openid_configuration')) {
|
|
29
|
+
options.openid_configuration = options.store.get('openid_configuration')
|
|
30
|
+
}
|
|
31
|
+
if (!options.client_info.client_id && options.store.has('client_info')) {
|
|
32
|
+
options.client_info = options.store.get('client_info')
|
|
33
|
+
}
|
|
23
34
|
|
|
24
35
|
return async (req, next) => {
|
|
25
36
|
let res
|
|
@@ -39,6 +50,7 @@ export default function oidcmw(options={}) {
|
|
|
39
50
|
options.openid_configuration = await discover({
|
|
40
51
|
issuer: options.issuer
|
|
41
52
|
})
|
|
53
|
+
options.store.set('openid_configuration', options.openid_configuration)
|
|
42
54
|
}
|
|
43
55
|
|
|
44
56
|
if (!options.client_info?.client_id) {
|
|
@@ -50,6 +62,7 @@ export default function oidcmw(options={}) {
|
|
|
50
62
|
registration_endpoint: options.openid_configuration.registration_endpoint,
|
|
51
63
|
client_info: options.client_info
|
|
52
64
|
})
|
|
65
|
+
options.store.set('client_info', options.client_info)
|
|
53
66
|
}
|
|
54
67
|
|
|
55
68
|
// now initialize an oauth2 client stack, using options.client as default
|
|
@@ -62,10 +75,12 @@ export default function oidcmw(options={}) {
|
|
|
62
75
|
oauth2_configuration: {
|
|
63
76
|
client_id: options.client_info.client_id,
|
|
64
77
|
client_secret: options.client_info.client_secret,
|
|
78
|
+
code_verifier: false, //disable pkce
|
|
65
79
|
grant_type: 'authorization_code',
|
|
66
80
|
authorization_endpoint: options.openid_configuration.authorization_endpoint,
|
|
67
81
|
token_endpoint: options.openid_configuration.token_endpoint,
|
|
68
|
-
scope: options.openid_configuration.scope || 'openid'
|
|
82
|
+
scope: options.openid_configuration.scope || 'openid',
|
|
83
|
+
redirect_uri: options.client_info.redirect_uris[0] //FIXME: find the best match?
|
|
69
84
|
}
|
|
70
85
|
}
|
|
71
86
|
//...
|