@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/dist/browser-dev.js
CHANGED
|
@@ -986,7 +986,7 @@
|
|
|
986
986
|
// note: this allows path components in the options.issuer url
|
|
987
987
|
configURL
|
|
988
988
|
);
|
|
989
|
-
const openid_config = response2.body;
|
|
989
|
+
const openid_config = response2.body[Symbol.metroSource];
|
|
990
990
|
assert(openid_config, openid_provider_metadata);
|
|
991
991
|
assert(openid_config.issuer, options.issuer);
|
|
992
992
|
return openid_config;
|
|
@@ -1500,6 +1500,26 @@
|
|
|
1500
1500
|
}
|
|
1501
1501
|
};
|
|
1502
1502
|
|
|
1503
|
+
// src/oidc.store.mjs
|
|
1504
|
+
function oidcStore(site) {
|
|
1505
|
+
let store;
|
|
1506
|
+
if (typeof localStorage !== "undefined") {
|
|
1507
|
+
store = {
|
|
1508
|
+
get: (name) => JSON.parse(localStorage.getItem("metro/oidc:" + site + ":" + name)),
|
|
1509
|
+
set: (name, value) => localStorage.setItem("metro/oidc:" + site + ":" + name, JSON.stringify(value)),
|
|
1510
|
+
has: (name) => localStorage.getItem("metro/oidc:" + site + ":" + name) !== null
|
|
1511
|
+
};
|
|
1512
|
+
} else {
|
|
1513
|
+
let storeMap = /* @__PURE__ */ new Map();
|
|
1514
|
+
store = {
|
|
1515
|
+
get: (name) => JSON.parse(storeMap.get("metro/oidc:" + site + ":" + name) || null),
|
|
1516
|
+
set: (name, value) => storeMap.set("metro/oidc:" + site + ":" + name, JSON.stringify(value)),
|
|
1517
|
+
has: (name) => storeMap.has("metro/oidc:" + site + ":" + name)
|
|
1518
|
+
};
|
|
1519
|
+
}
|
|
1520
|
+
return store;
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1503
1523
|
// src/oidcmw.mjs
|
|
1504
1524
|
function oidcmw(options = {}) {
|
|
1505
1525
|
const defaultOptions = {
|
|
@@ -1507,6 +1527,23 @@
|
|
|
1507
1527
|
force_authorization: false
|
|
1508
1528
|
};
|
|
1509
1529
|
options = Object.assign({}, defaultOptions, options);
|
|
1530
|
+
assert(options, {
|
|
1531
|
+
client: Required(instanceOf(everything_default.client().constructor)),
|
|
1532
|
+
// required because it is set in defaultOptions
|
|
1533
|
+
client_info: Required(),
|
|
1534
|
+
issuer: Required(validURL),
|
|
1535
|
+
oauth2: Optional({}),
|
|
1536
|
+
openid_configuration: Optional()
|
|
1537
|
+
});
|
|
1538
|
+
if (!options.store) {
|
|
1539
|
+
options.store = oidcStore(options.issuer);
|
|
1540
|
+
}
|
|
1541
|
+
if (!options.openid_configuration && options.store.has("openid_configuration")) {
|
|
1542
|
+
options.openid_configuration = options.store.get("openid_configuration");
|
|
1543
|
+
}
|
|
1544
|
+
if (!options.client_info.client_id && options.store.has("client_info")) {
|
|
1545
|
+
options.client_info = options.store.get("client_info");
|
|
1546
|
+
}
|
|
1510
1547
|
return async (req, next) => {
|
|
1511
1548
|
let res;
|
|
1512
1549
|
if (!options.force_authorization) {
|
|
@@ -1525,6 +1562,7 @@
|
|
|
1525
1562
|
options.openid_configuration = await oidcDiscovery({
|
|
1526
1563
|
issuer: options.issuer
|
|
1527
1564
|
});
|
|
1565
|
+
options.store.set("openid_configuration", options.openid_configuration);
|
|
1528
1566
|
}
|
|
1529
1567
|
if (!options.client_info?.client_id) {
|
|
1530
1568
|
assert(options.client_info?.client_name, Required());
|
|
@@ -1535,6 +1573,7 @@
|
|
|
1535
1573
|
registration_endpoint: options.openid_configuration.registration_endpoint,
|
|
1536
1574
|
client_info: options.client_info
|
|
1537
1575
|
});
|
|
1576
|
+
options.store.set("client_info", options.client_info);
|
|
1538
1577
|
}
|
|
1539
1578
|
const oauth2Options = Object.assign(
|
|
1540
1579
|
{
|
|
@@ -1544,10 +1583,14 @@
|
|
|
1544
1583
|
oauth2_configuration: {
|
|
1545
1584
|
client_id: options.client_info.client_id,
|
|
1546
1585
|
client_secret: options.client_info.client_secret,
|
|
1586
|
+
code_verifier: false,
|
|
1587
|
+
//disable pkce
|
|
1547
1588
|
grant_type: "authorization_code",
|
|
1548
1589
|
authorization_endpoint: options.openid_configuration.authorization_endpoint,
|
|
1549
1590
|
token_endpoint: options.openid_configuration.token_endpoint,
|
|
1550
|
-
scope: options.openid_configuration.scope || "openid"
|
|
1591
|
+
scope: options.openid_configuration.scope || "openid",
|
|
1592
|
+
redirect_uri: options.client_info.redirect_uris[0]
|
|
1593
|
+
//FIXME: find the best match?
|
|
1551
1594
|
}
|
|
1552
1595
|
}
|
|
1553
1596
|
//...
|