@muze-nl/metro-oidc 0.3.4 → 0.3.6
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/README.md +4 -2
- package/dist/browser.js +23 -12
- package/dist/browser.js.map +2 -2
- package/dist/browser.min.js +1 -1
- package/dist/browser.min.js.map +3 -3
- package/package.json +2 -2
- package/src/oidcmw.mjs +9 -1
package/README.md
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
The OpenID Connect middleware allows you to configure a [metro client](https://github.com/muze-nl/metro) to handle authorization and authentication using OpenID Connect:
|
|
6
6
|
|
|
7
7
|
```javascript
|
|
8
|
-
import
|
|
8
|
+
import oidc from '@muze-nl/metro-oidc'
|
|
9
9
|
|
|
10
10
|
const client = metro.client('https://oauth2api.example.com')
|
|
11
|
-
.with( oidcmw({
|
|
11
|
+
.with( oidc.oidcmw({
|
|
12
12
|
client_info: {
|
|
13
13
|
client_name: 'My Client',
|
|
14
14
|
redirect_uris: [
|
|
@@ -23,6 +23,8 @@ async function fetchMovies() {
|
|
|
23
23
|
}
|
|
24
24
|
````
|
|
25
25
|
|
|
26
|
+
_Note_: If your client has more than 1 possible `redirect_uri`, all will be used to register that client, but the first one will be used for this session. So make sure to put the `redirect_uri` you want to use now at `redirect_uris[0]``.
|
|
27
|
+
|
|
26
28
|
The OIDC middleware will automatically discover the configuration of the issuer, as well as do a dynamic client registration, if you haven't set a `client_info.client_id`.
|
|
27
29
|
It will then configure the correct OAuth2 settings and handle the request with [metro oauth2](https://github.com/muze-nl/metro-oauth2) middleware. It may redirect the browser to let the user login with the OIDC issuer. You can skip the automatic configuration step, if you provide the `openid_configuration` parameter set yourself. If you don't, the oidcmw middleware will only run the discovery process once, and store the information in localStorage. The same with the client_info and dynamic registration.
|
|
28
30
|
|
package/dist/browser.js
CHANGED
|
@@ -1093,12 +1093,12 @@
|
|
|
1093
1093
|
search.response_mode = oauth22.response_mode;
|
|
1094
1094
|
}
|
|
1095
1095
|
options.state.set(search.state);
|
|
1096
|
-
if (oauth22.client_secret) {
|
|
1097
|
-
search.client_secret = oauth22.client_secret;
|
|
1098
|
-
}
|
|
1099
1096
|
if (oauth22.code_verifier) {
|
|
1097
|
+
options.tokens.set("code_verifier", oauth22.code_verifier);
|
|
1100
1098
|
search.code_challenge = await generateCodeChallenge(oauth22.code_verifier);
|
|
1101
1099
|
search.code_challenge_method = "S256";
|
|
1100
|
+
} else if (oauth22.client_secret) {
|
|
1101
|
+
search.client_secret = oauth22.client_secret;
|
|
1102
1102
|
}
|
|
1103
1103
|
if (oauth22.scope) {
|
|
1104
1104
|
search.scope = oauth22.scope;
|
|
@@ -1121,10 +1121,10 @@
|
|
|
1121
1121
|
grant_type: grant_type || oauth22.grant_type,
|
|
1122
1122
|
client_id: oauth22.client_id
|
|
1123
1123
|
};
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
if (oauth22.client_secret) {
|
|
1124
|
+
const code_verifier = options.tokens.get("code_verifier");
|
|
1125
|
+
if (code_verifier) {
|
|
1126
|
+
params2.code_verifier = code_verifier;
|
|
1127
|
+
} else if (oauth22.client_secret) {
|
|
1128
1128
|
params2.client_secret = oauth22.client_secret;
|
|
1129
1129
|
}
|
|
1130
1130
|
if (oauth22.scope) {
|
|
@@ -1167,9 +1167,15 @@
|
|
|
1167
1167
|
throw new TypeError("Unknown expires type " + duration);
|
|
1168
1168
|
}
|
|
1169
1169
|
function generateCodeVerifier(size = 64) {
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1170
|
+
size = Math.min(43, Math.max(128, size));
|
|
1171
|
+
const allowed = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
|
|
1172
|
+
const random = new Uint8Array(size);
|
|
1173
|
+
globalThis.crypto.getRandomValues(random);
|
|
1174
|
+
const code_verifier = Array.from(random).map((b) => {
|
|
1175
|
+
let c = allowed[b % allowed.length];
|
|
1176
|
+
return c;
|
|
1177
|
+
}).join("");
|
|
1178
|
+
return code_verifier;
|
|
1173
1179
|
}
|
|
1174
1180
|
async function generateCodeChallenge(code_verifier) {
|
|
1175
1181
|
const encoder2 = new TextEncoder();
|
|
@@ -1772,7 +1778,7 @@
|
|
|
1772
1778
|
}
|
|
1773
1779
|
|
|
1774
1780
|
// node_modules/@muze-nl/metro-oauth2/src/browser.mjs
|
|
1775
|
-
var oauth2 = Object.assign(oauth2_exports, {
|
|
1781
|
+
var oauth2 = Object.assign({}, oauth2_exports, {
|
|
1776
1782
|
oauth2mw,
|
|
1777
1783
|
mockserver: oauth2_mockserver_exports,
|
|
1778
1784
|
discover: oauth2_discovery_exports,
|
|
@@ -2038,11 +2044,16 @@
|
|
|
2038
2044
|
scope,
|
|
2039
2045
|
//FIXME: should only use scopes supported by server
|
|
2040
2046
|
redirect_uri: options.client_info.redirect_uris[0]
|
|
2041
|
-
//FIXME: find the best match?
|
|
2042
2047
|
}
|
|
2043
2048
|
}
|
|
2044
2049
|
//...
|
|
2045
2050
|
);
|
|
2051
|
+
const pkceSupported = options.openid_configuration.code_challenge_methods_supported.length;
|
|
2052
|
+
if (pkceSupported) {
|
|
2053
|
+
delete oauth2Options.oauth2_configuration.client_secret;
|
|
2054
|
+
} else {
|
|
2055
|
+
oauth2Options.oauth2_configuration.code_verifier = false;
|
|
2056
|
+
}
|
|
2046
2057
|
const storeIdToken = async (req2, next2) => {
|
|
2047
2058
|
const res2 = await next2(req2);
|
|
2048
2059
|
const contentType = res2.headers.get("content-type");
|