@muze-nl/metro-oidc 0.1.1 → 0.1.3
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 +66 -5
- package/dist/browser-dev.js.map +4 -4
- package/dist/browser.js +1 -1
- package/dist/browser.js.map +4 -4
- package/package.json +2 -2
- package/src/browser.mjs +3 -2
- package/src/oidc.discovery.mjs +1 -1
- package/src/oidc.store.mjs +18 -0
- package/src/oidcmw.mjs +28 -9
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;
|
|
@@ -1169,8 +1169,8 @@
|
|
|
1169
1169
|
has: () => localStorage.getItem("metro/state:" + site) !== null
|
|
1170
1170
|
};
|
|
1171
1171
|
localTokens = {
|
|
1172
|
-
get: (name) => localStorage.getItem(site + ":" + name),
|
|
1173
|
-
set: (name, value) => localStorage.setItem(site + ":" + name, value),
|
|
1172
|
+
get: (name) => JSON.parse(localStorage.getItem(site + ":" + name)),
|
|
1173
|
+
set: (name, value) => localStorage.setItem(site + ":" + name, JSON.stringify(value)),
|
|
1174
1174
|
has: (name) => localStorage.getItem(site + ":" + name) !== null
|
|
1175
1175
|
};
|
|
1176
1176
|
} else {
|
|
@@ -1499,6 +1499,40 @@
|
|
|
1499
1499
|
return randomState;
|
|
1500
1500
|
}
|
|
1501
1501
|
};
|
|
1502
|
+
function isRedirected() {
|
|
1503
|
+
let url2 = new URL(document.location.href);
|
|
1504
|
+
if (!url2.searchParams.has("code")) {
|
|
1505
|
+
if (url2.hash) {
|
|
1506
|
+
let query = url2.hash.substr(1);
|
|
1507
|
+
params = new URLSearchParams("?" + query);
|
|
1508
|
+
if (params.has("code")) {
|
|
1509
|
+
return true;
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
return false;
|
|
1513
|
+
}
|
|
1514
|
+
return true;
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
// src/oidc.store.mjs
|
|
1518
|
+
function oidcStore(site) {
|
|
1519
|
+
let store;
|
|
1520
|
+
if (typeof localStorage !== "undefined") {
|
|
1521
|
+
store = {
|
|
1522
|
+
get: (name) => JSON.parse(localStorage.getItem("metro/oidc:" + site + ":" + name)),
|
|
1523
|
+
set: (name, value) => localStorage.setItem("metro/oidc:" + site + ":" + name, JSON.stringify(value)),
|
|
1524
|
+
has: (name) => localStorage.getItem("metro/oidc:" + site + ":" + name) !== null
|
|
1525
|
+
};
|
|
1526
|
+
} else {
|
|
1527
|
+
let storeMap = /* @__PURE__ */ new Map();
|
|
1528
|
+
store = {
|
|
1529
|
+
get: (name) => JSON.parse(storeMap.get("metro/oidc:" + site + ":" + name) || null),
|
|
1530
|
+
set: (name, value) => storeMap.set("metro/oidc:" + site + ":" + name, JSON.stringify(value)),
|
|
1531
|
+
has: (name) => storeMap.has("metro/oidc:" + site + ":" + name)
|
|
1532
|
+
};
|
|
1533
|
+
}
|
|
1534
|
+
return store;
|
|
1535
|
+
}
|
|
1502
1536
|
|
|
1503
1537
|
// src/oidcmw.mjs
|
|
1504
1538
|
function oidcmw(options = {}) {
|
|
@@ -1507,6 +1541,23 @@
|
|
|
1507
1541
|
force_authorization: false
|
|
1508
1542
|
};
|
|
1509
1543
|
options = Object.assign({}, defaultOptions, options);
|
|
1544
|
+
assert(options, {
|
|
1545
|
+
client: Required(instanceOf(everything_default.client().constructor)),
|
|
1546
|
+
// required because it is set in defaultOptions
|
|
1547
|
+
client_info: Required(),
|
|
1548
|
+
issuer: Required(validURL),
|
|
1549
|
+
oauth2: Optional({}),
|
|
1550
|
+
openid_configuration: Optional()
|
|
1551
|
+
});
|
|
1552
|
+
if (!options.store) {
|
|
1553
|
+
options.store = oidcStore(options.issuer);
|
|
1554
|
+
}
|
|
1555
|
+
if (!options.openid_configuration && options.store.has("openid_configuration")) {
|
|
1556
|
+
options.openid_configuration = options.store.get("openid_configuration");
|
|
1557
|
+
}
|
|
1558
|
+
if (!options.client_info.client_id && options.store.has("client_info")) {
|
|
1559
|
+
options.client_info = options.store.get("client_info");
|
|
1560
|
+
}
|
|
1510
1561
|
return async (req, next) => {
|
|
1511
1562
|
let res;
|
|
1512
1563
|
if (!options.force_authorization) {
|
|
@@ -1525,6 +1576,7 @@
|
|
|
1525
1576
|
options.openid_configuration = await oidcDiscovery({
|
|
1526
1577
|
issuer: options.issuer
|
|
1527
1578
|
});
|
|
1579
|
+
options.store.set("openid_configuration", options.openid_configuration);
|
|
1528
1580
|
}
|
|
1529
1581
|
if (!options.client_info?.client_id) {
|
|
1530
1582
|
assert(options.client_info?.client_name, Required());
|
|
@@ -1535,6 +1587,7 @@
|
|
|
1535
1587
|
registration_endpoint: options.openid_configuration.registration_endpoint,
|
|
1536
1588
|
client_info: options.client_info
|
|
1537
1589
|
});
|
|
1590
|
+
options.store.set("client_info", options.client_info);
|
|
1538
1591
|
}
|
|
1539
1592
|
const oauth2Options = Object.assign(
|
|
1540
1593
|
{
|
|
@@ -1544,10 +1597,14 @@
|
|
|
1544
1597
|
oauth2_configuration: {
|
|
1545
1598
|
client_id: options.client_info.client_id,
|
|
1546
1599
|
client_secret: options.client_info.client_secret,
|
|
1600
|
+
code_verifier: false,
|
|
1601
|
+
//disable pkce
|
|
1547
1602
|
grant_type: "authorization_code",
|
|
1548
1603
|
authorization_endpoint: options.openid_configuration.authorization_endpoint,
|
|
1549
1604
|
token_endpoint: options.openid_configuration.token_endpoint,
|
|
1550
|
-
scope: options.openid_configuration.scope || "openid"
|
|
1605
|
+
scope: options.openid_configuration.scope || "openid",
|
|
1606
|
+
redirect_uri: options.client_info.redirect_uris[0]
|
|
1607
|
+
//FIXME: find the best match?
|
|
1551
1608
|
}
|
|
1552
1609
|
}
|
|
1553
1610
|
//...
|
|
@@ -1557,12 +1614,16 @@
|
|
|
1557
1614
|
return res;
|
|
1558
1615
|
};
|
|
1559
1616
|
}
|
|
1617
|
+
function isRedirected2() {
|
|
1618
|
+
return isRedirected();
|
|
1619
|
+
}
|
|
1560
1620
|
|
|
1561
1621
|
// src/browser.mjs
|
|
1562
1622
|
var oidc = {
|
|
1563
1623
|
discover: oidcDiscovery,
|
|
1564
1624
|
register,
|
|
1565
|
-
oidcmw
|
|
1625
|
+
oidcmw,
|
|
1626
|
+
isRedirected: isRedirected2
|
|
1566
1627
|
};
|
|
1567
1628
|
globalThis.oidc = oidc;
|
|
1568
1629
|
})();
|