ep_openid_connect 3.0.25 → 3.0.26
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/index.js +13 -4
- package/package.json +1 -1
- package/static/tests/backend/specs/tests.js +10 -0
package/index.js
CHANGED
|
@@ -52,6 +52,15 @@ const validSettings = new Ajv().compile({
|
|
|
52
52
|
const ep = (endpoint) => `/ep_openid_connect/${endpoint}`;
|
|
53
53
|
const endpointUrl = (endpoint) => new URL(ep(endpoint).substr(1), settings.base_url).toString();
|
|
54
54
|
|
|
55
|
+
const callbackUrlFromRequest = (req) => {
|
|
56
|
+
const callbackUrl = new URL(endpointUrl('callback'));
|
|
57
|
+
const requestUrl = new URL(req.originalUrl || req.url, settings.base_url);
|
|
58
|
+
for (const [key, value] of requestUrl.searchParams) {
|
|
59
|
+
callbackUrl.searchParams.append(key, value);
|
|
60
|
+
}
|
|
61
|
+
return callbackUrl;
|
|
62
|
+
};
|
|
63
|
+
|
|
55
64
|
const validateSubClaim = (sub) => {
|
|
56
65
|
if (typeof sub !== 'string' || // 'sub' claim must exist as a string per OIDC spec.
|
|
57
66
|
sub === '' || // Empty string doesn't make sense.
|
|
@@ -82,8 +91,8 @@ const discoverConfig = async (issuerUrl, clientId, clientAuth) => {
|
|
|
82
91
|
// openid-client@6 rejects http:// issuers by default; opt back in for
|
|
83
92
|
// localhost / private-network providers (matches v5 behaviour).
|
|
84
93
|
const options = url.protocol === 'http:'
|
|
85
|
-
|
|
86
|
-
|
|
94
|
+
? {execute: [oidc.allowInsecureRequests]}
|
|
95
|
+
: undefined;
|
|
87
96
|
try {
|
|
88
97
|
return await oidc.discovery(url, clientId, undefined, clientAuth, options);
|
|
89
98
|
} catch (err) {
|
|
@@ -186,8 +195,7 @@ exports.expressCreateServer = (hookName, {app}) => {
|
|
|
186
195
|
}
|
|
187
196
|
const oidcSession = req.session.ep_openid_connect || {};
|
|
188
197
|
if (oidcSession.callbackChecks == null) throw new Error('missing authentication checks');
|
|
189
|
-
const
|
|
190
|
-
const tokens = await oidc.authorizationCodeGrant(oidcConfig, currentUrl, {
|
|
198
|
+
const tokens = await oidc.authorizationCodeGrant(oidcConfig, callbackUrlFromRequest(req), {
|
|
191
199
|
expectedNonce: oidcSession.callbackChecks.nonce,
|
|
192
200
|
expectedState: oidcSession.callbackChecks.state,
|
|
193
201
|
pkceCodeVerifier: oidcSession.callbackChecks.code_verifier,
|
|
@@ -326,6 +334,7 @@ exports.preAuthorize = (hookName, {req}) => {
|
|
|
326
334
|
};
|
|
327
335
|
|
|
328
336
|
exports.exportedForTestingOnly = {
|
|
337
|
+
callbackUrlFromRequest,
|
|
329
338
|
defaultSettings,
|
|
330
339
|
validSettings,
|
|
331
340
|
};
|
package/package.json
CHANGED
|
@@ -113,6 +113,16 @@ describe(__filename, function () {
|
|
|
113
113
|
});
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
+
it('callback URL uses configured base URL with request query parameters', async function () {
|
|
117
|
+
const callbackUrl = epOpenidConnect.exportedForTestingOnly.callbackUrlFromRequest({
|
|
118
|
+
originalUrl: '/ep_openid_connect/callback?code=the_code&state=the_state',
|
|
119
|
+
});
|
|
120
|
+
const expectedUrl = new URL('/ep_openid_connect/callback', pluginSettings.base_url);
|
|
121
|
+
expectedUrl.searchParams.set('code', 'the_code');
|
|
122
|
+
expectedUrl.searchParams.set('state', 'the_state');
|
|
123
|
+
assert.equal(callbackUrl.toString(), expectedUrl.toString());
|
|
124
|
+
});
|
|
125
|
+
|
|
116
126
|
it('normalUser can create and edit a pad', async function () {
|
|
117
127
|
const padId = common.randomString();
|
|
118
128
|
const url = new URL(`/p/${padId}`, common.baseUrl).toString();
|