@muze-nl/metro-oidc 0.1.5 → 0.2.0
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.js +79 -50
- package/dist/browser.js.map +3 -3
- package/dist/browser.min.js +1 -1
- package/dist/browser.min.js.map +4 -4
- package/package.json +2 -2
- package/src/oidcmw.mjs +5 -2
package/dist/browser.js
CHANGED
|
@@ -1382,7 +1382,7 @@
|
|
|
1382
1382
|
}
|
|
1383
1383
|
async function fetchAccessToken() {
|
|
1384
1384
|
if (oauth22.grant_type === "authorization_code" && !options.tokens.has("authorization_code")) {
|
|
1385
|
-
let authReqURL = getAuthorizationCodeURL();
|
|
1385
|
+
let authReqURL = await getAuthorizationCodeURL();
|
|
1386
1386
|
if (!options.callbacks.authorize || typeof options.callbacks.authorize !== "function") {
|
|
1387
1387
|
throw everything_default.metroError("oauth2mw: oauth2 with grant_type:authorization_code requires a callback function in client options.options.callbacks.authorize");
|
|
1388
1388
|
}
|
|
@@ -1437,7 +1437,7 @@
|
|
|
1437
1437
|
}
|
|
1438
1438
|
return data;
|
|
1439
1439
|
}
|
|
1440
|
-
function getAuthorizationCodeURL() {
|
|
1440
|
+
async function getAuthorizationCodeURL() {
|
|
1441
1441
|
if (!oauth22.authorization_endpoint) {
|
|
1442
1442
|
throw everything_default.metroError("oauth2mw: Missing options.oauth2_configuration.authorization_endpoint");
|
|
1443
1443
|
}
|
|
@@ -1455,17 +1455,26 @@
|
|
|
1455
1455
|
state: oauth22.state || createState(40)
|
|
1456
1456
|
// OAuth2.1 RFC says optional, but its a good idea to always add/check it
|
|
1457
1457
|
};
|
|
1458
|
+
if (oauth22.response_type) {
|
|
1459
|
+
search.response_type = oauth22.response_type;
|
|
1460
|
+
}
|
|
1461
|
+
if (oauth22.response_mode) {
|
|
1462
|
+
search.response_mode = oauth22.response_mode;
|
|
1463
|
+
}
|
|
1458
1464
|
options.state.set(search.state);
|
|
1459
1465
|
if (oauth22.client_secret) {
|
|
1460
1466
|
search.client_secret = oauth22.client_secret;
|
|
1461
1467
|
}
|
|
1462
1468
|
if (oauth22.code_verifier) {
|
|
1463
|
-
search.code_challenge = generateCodeChallenge(oauth22.code_verifier);
|
|
1469
|
+
search.code_challenge = base64url_encode(await generateCodeChallenge(oauth22.code_verifier));
|
|
1464
1470
|
search.code_challenge_method = "S256";
|
|
1465
1471
|
}
|
|
1466
1472
|
if (oauth22.scope) {
|
|
1467
1473
|
search.scope = oauth22.scope;
|
|
1468
1474
|
}
|
|
1475
|
+
if (oauth22.prompt) {
|
|
1476
|
+
search.prompt = oauth22.prompt;
|
|
1477
|
+
}
|
|
1469
1478
|
return everything_default.url(url2, { search });
|
|
1470
1479
|
}
|
|
1471
1480
|
function getAccessTokenRequest(grant_type = null) {
|
|
@@ -1782,6 +1791,57 @@
|
|
|
1782
1791
|
throw everything_default.metroError("metro.oidcmw: Error while fetching " + issuer + ".wellknown/oauth_authorization_server", res);
|
|
1783
1792
|
}
|
|
1784
1793
|
|
|
1794
|
+
// node_modules/@muze-nl/metro-oauth2/src/keysstore.mjs
|
|
1795
|
+
function keysStore() {
|
|
1796
|
+
return new Promise((resolve, reject) => {
|
|
1797
|
+
const request2 = globalThis.indexedDB.open("metro", 1);
|
|
1798
|
+
request2.onupgradeneeded = () => request2.result.createObjectStore("keyPairs", { keyPath: "domain" });
|
|
1799
|
+
request2.onerror = (event) => {
|
|
1800
|
+
reject(event);
|
|
1801
|
+
};
|
|
1802
|
+
request2.onsuccess = (event) => {
|
|
1803
|
+
const db = event.target.result;
|
|
1804
|
+
resolve({
|
|
1805
|
+
set: function(value, key) {
|
|
1806
|
+
return new Promise((resolve2, reject2) => {
|
|
1807
|
+
const tx = db.transaction("keyPairs", "readwrite", { durability: "strict" });
|
|
1808
|
+
const objectStore = tx.objectStore("keyPairs");
|
|
1809
|
+
tx.oncomplete = () => {
|
|
1810
|
+
resolve2();
|
|
1811
|
+
};
|
|
1812
|
+
tx.onerror = reject2;
|
|
1813
|
+
objectStore.put(value, key);
|
|
1814
|
+
});
|
|
1815
|
+
},
|
|
1816
|
+
get: function(key) {
|
|
1817
|
+
return new Promise((resolve2, reject2) => {
|
|
1818
|
+
const tx = db.transaction("keyPairs", "readonly");
|
|
1819
|
+
const objectStore = tx.objectStore("keyPairs");
|
|
1820
|
+
const request3 = objectStore.get(key);
|
|
1821
|
+
request3.onsuccess = () => {
|
|
1822
|
+
resolve2(request3.result);
|
|
1823
|
+
};
|
|
1824
|
+
request3.onerror = reject2;
|
|
1825
|
+
tx.onerror = reject2;
|
|
1826
|
+
});
|
|
1827
|
+
},
|
|
1828
|
+
clear: function() {
|
|
1829
|
+
return new Promise((resolve2, reject2) => {
|
|
1830
|
+
const tx = db.transaction("keyPairs", "readwrite");
|
|
1831
|
+
const objectStore = tx.objectStore("keyPairs");
|
|
1832
|
+
const request3 = objectStore.clear();
|
|
1833
|
+
request3.onsuccess = () => {
|
|
1834
|
+
resolve2();
|
|
1835
|
+
};
|
|
1836
|
+
request3.onerror = reject2;
|
|
1837
|
+
tx.onerror = reject2;
|
|
1838
|
+
});
|
|
1839
|
+
}
|
|
1840
|
+
});
|
|
1841
|
+
};
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1785
1845
|
// node_modules/dpop/build/index.js
|
|
1786
1846
|
var encoder = new TextEncoder();
|
|
1787
1847
|
var decoder = new TextDecoder();
|
|
@@ -1982,62 +2042,24 @@
|
|
|
1982
2042
|
return crypto.subtle.generateKey(algorithm, options?.extractable ?? false, ["sign", "verify"]);
|
|
1983
2043
|
}
|
|
1984
2044
|
|
|
1985
|
-
// node_modules/@muze-nl/metro-oauth2/src/keysstore.mjs
|
|
1986
|
-
function keysStore() {
|
|
1987
|
-
return new Promise((resolve, reject) => {
|
|
1988
|
-
const request2 = globalThis.indexedDB.open("metro", 1);
|
|
1989
|
-
request2.onupgradeneeded = () => request2.result.createObjectStore("keyPairs", { keyPath: "domain" });
|
|
1990
|
-
request2.onerror = (event) => {
|
|
1991
|
-
reject(event);
|
|
1992
|
-
};
|
|
1993
|
-
request2.onsuccess = (event) => {
|
|
1994
|
-
const db = event.target.result;
|
|
1995
|
-
resolve({
|
|
1996
|
-
set: function(value, key) {
|
|
1997
|
-
return new Promise((resolve2, reject2) => {
|
|
1998
|
-
const tx = db.transaction("keyPairs", "readwriteflush", { durability: "strict" });
|
|
1999
|
-
const objectStore = tx.objectStore("keyPairs");
|
|
2000
|
-
tx.oncomplete = () => {
|
|
2001
|
-
resolve2();
|
|
2002
|
-
};
|
|
2003
|
-
tx.onerror = reject2;
|
|
2004
|
-
objectStore.put(value, key);
|
|
2005
|
-
});
|
|
2006
|
-
},
|
|
2007
|
-
get: function(key) {
|
|
2008
|
-
return new Promise((resolve2, reject2) => {
|
|
2009
|
-
const tx = db.transaction("keyPairs", "readonly");
|
|
2010
|
-
const objectStore = tx.objectStore("keyPairs");
|
|
2011
|
-
const request3 = objectStore.get(key);
|
|
2012
|
-
request3.onsuccess = () => {
|
|
2013
|
-
resolve2(request3.result);
|
|
2014
|
-
};
|
|
2015
|
-
request3.onerror = reject2;
|
|
2016
|
-
tx.onerror = reject2;
|
|
2017
|
-
});
|
|
2018
|
-
}
|
|
2019
|
-
});
|
|
2020
|
-
};
|
|
2021
|
-
});
|
|
2022
|
-
}
|
|
2023
|
-
|
|
2024
2045
|
// node_modules/@muze-nl/metro-oauth2/src/oauth2.dpop.mjs
|
|
2025
2046
|
function dpopmw(options) {
|
|
2026
2047
|
assert2(options, {
|
|
2048
|
+
site: Required2(validURL2),
|
|
2027
2049
|
authorization_endpoint: Required2(validURL2),
|
|
2028
2050
|
token_endpoint: Required2(validURL2)
|
|
2029
2051
|
// dpop_signing_alg_values_supported: Required([]) // this property is unfortunately rarely supported
|
|
2030
2052
|
});
|
|
2031
2053
|
return async (req, next) => {
|
|
2032
2054
|
const keys = await keysStore();
|
|
2033
|
-
|
|
2034
|
-
let keyInfo = await keys.get(url2.host);
|
|
2055
|
+
let keyInfo = await keys.get(options.site);
|
|
2035
2056
|
if (!keyInfo) {
|
|
2036
2057
|
let keyPair = await generateKeyPair("ES256");
|
|
2037
|
-
keyInfo = { domain:
|
|
2058
|
+
keyInfo = { domain: options.site, keyPair };
|
|
2038
2059
|
await keys.set(keyInfo);
|
|
2039
2060
|
}
|
|
2040
|
-
|
|
2061
|
+
const url2 = everything_default.url(req.url);
|
|
2062
|
+
if (req.url.startsWith(options.authorization_endpoint) || req.url.startsWith(options.token_endpoint)) {
|
|
2041
2063
|
const dpopHeader = await DPoP(keyInfo.keyPair, req.url, req.method);
|
|
2042
2064
|
req = req.with({
|
|
2043
2065
|
headers: {
|
|
@@ -2050,6 +2072,8 @@
|
|
|
2050
2072
|
const dpopHeader = await DPoP(keyInfo.keyPair, req.url, req.method, nonce, accessToken);
|
|
2051
2073
|
req = req.with({
|
|
2052
2074
|
headers: {
|
|
2075
|
+
"Authorization": "DPoP " + accessToken,
|
|
2076
|
+
//solidcommunity server sends accesstoken with type Bearer
|
|
2053
2077
|
"DPoP": dpopHeader
|
|
2054
2078
|
}
|
|
2055
2079
|
});
|
|
@@ -2067,8 +2091,10 @@
|
|
|
2067
2091
|
mockserver: oauth2_mockserver_exports,
|
|
2068
2092
|
discovery: oauth2_discovery_exports,
|
|
2069
2093
|
tokenstore: tokenStore,
|
|
2070
|
-
dpopmw
|
|
2094
|
+
dpopmw,
|
|
2095
|
+
keysstore: keysStore
|
|
2071
2096
|
});
|
|
2097
|
+
globalThis.oauth2 = oauth2;
|
|
2072
2098
|
var browser_default = oauth2;
|
|
2073
2099
|
|
|
2074
2100
|
// src/oidc.store.mjs
|
|
@@ -2146,6 +2172,7 @@
|
|
|
2146
2172
|
});
|
|
2147
2173
|
options.store.set("client_info", options.client_info);
|
|
2148
2174
|
}
|
|
2175
|
+
const scope = options.scope || "openid";
|
|
2149
2176
|
const oauth2Options = Object.assign(
|
|
2150
2177
|
{
|
|
2151
2178
|
site: options.issuer,
|
|
@@ -2154,12 +2181,13 @@
|
|
|
2154
2181
|
oauth2_configuration: {
|
|
2155
2182
|
client_id: options.client_info.client_id,
|
|
2156
2183
|
client_secret: options.client_info.client_secret,
|
|
2157
|
-
code_verifier: false,
|
|
2158
|
-
//FIXME: detect pkce support
|
|
2159
2184
|
grant_type: "authorization_code",
|
|
2185
|
+
response_type: "code",
|
|
2186
|
+
response_mode: "query",
|
|
2160
2187
|
authorization_endpoint: options.openid_configuration.authorization_endpoint,
|
|
2161
2188
|
token_endpoint: options.openid_configuration.token_endpoint,
|
|
2162
|
-
scope
|
|
2189
|
+
scope,
|
|
2190
|
+
//FIXME: should only use scopes supported by server
|
|
2163
2191
|
redirect_uri: options.client_info.redirect_uris[0]
|
|
2164
2192
|
//FIXME: find the best match?
|
|
2165
2193
|
}
|
|
@@ -2167,6 +2195,7 @@
|
|
|
2167
2195
|
//...
|
|
2168
2196
|
);
|
|
2169
2197
|
const dpopOptions = {
|
|
2198
|
+
site: options.issuer,
|
|
2170
2199
|
authorization_endpoint: options.openid_configuration.authorization_endpoint,
|
|
2171
2200
|
token_endpoint: options.openid_configuration.token_endpoint,
|
|
2172
2201
|
dpop_signing_alg_values_supported: options.openid_configuration.dpop_signing_alg_values_supported
|