@wbce-d9/api 12.0.0 → 12.0.1
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/auth/drivers/openid.js +30 -9
- package/package.json +5 -5
|
@@ -76,6 +76,14 @@ export class OpenIDAuthDriver extends BaseOAuthDriver {
|
|
|
76
76
|
const client = await this.client;
|
|
77
77
|
const codeChallenge = generators.codeChallenge(codeVerifier);
|
|
78
78
|
const paramsConfig = typeof this.config['params'] === 'object' ? this.config['params'] : {};
|
|
79
|
+
const redirectAfterLogin = additionalParams?.['redirect'];
|
|
80
|
+
delete additionalParams?.['redirect'];
|
|
81
|
+
let finalRedirectUri = this.redirectUrl;
|
|
82
|
+
if (redirectAfterLogin) {
|
|
83
|
+
const redirectUriWithParams = new URL(this.redirectUrl);
|
|
84
|
+
redirectUriWithParams.searchParams.set('redirect', redirectAfterLogin);
|
|
85
|
+
finalRedirectUri = redirectUriWithParams.toString();
|
|
86
|
+
}
|
|
79
87
|
return client.authorizationUrl({
|
|
80
88
|
scope: this.config['scope'] ?? 'openid profile email',
|
|
81
89
|
access_type: 'offline',
|
|
@@ -86,6 +94,7 @@ export class OpenIDAuthDriver extends BaseOAuthDriver {
|
|
|
86
94
|
// Some providers require state even with PKCE
|
|
87
95
|
state: codeChallenge,
|
|
88
96
|
nonce: codeChallenge,
|
|
97
|
+
redirect_uri: finalRedirectUri,
|
|
89
98
|
...additionalParams,
|
|
90
99
|
});
|
|
91
100
|
}
|
|
@@ -147,28 +156,40 @@ export function createOpenIDAuthRouter(providerName) {
|
|
|
147
156
|
expiresIn: '5m',
|
|
148
157
|
issuer: 'directus',
|
|
149
158
|
});
|
|
150
|
-
|
|
159
|
+
const additionalParams = { ...req.query };
|
|
160
|
+
delete additionalParams['prompt'];
|
|
161
|
+
const authUrl = await provider.generateAuthUrl(codeVerifier, prompt, additionalParams);
|
|
162
|
+
const urlParams = new URL(authUrl);
|
|
163
|
+
const state = urlParams.searchParams.get('state');
|
|
164
|
+
const cookieName = `openid.${providerName}.${state || ''}`;
|
|
165
|
+
res.cookie(cookieName, token, {
|
|
151
166
|
httpOnly: true,
|
|
152
167
|
sameSite: 'lax',
|
|
153
168
|
});
|
|
154
|
-
|
|
155
|
-
delete additionalParams['prompt'];
|
|
156
|
-
delete additionalParams['redirect'];
|
|
157
|
-
return res.redirect(await provider.generateAuthUrl(codeVerifier, prompt, additionalParams));
|
|
169
|
+
return res.redirect(authUrl);
|
|
158
170
|
}), respond);
|
|
159
171
|
router.post('/callback', express.urlencoded({ extended: false }), (req, res) => {
|
|
160
172
|
res.redirect(303, `./callback?${new URLSearchParams(req.body)}`);
|
|
161
173
|
}, respond);
|
|
162
174
|
router.get('/callback', asyncHandler(async (req, res, next) => {
|
|
175
|
+
const redirectUrl = req.query['redirect'];
|
|
176
|
+
const validRedirectUrl = isRedirectAllowedOnLogin(redirectUrl, providerName) ? redirectUrl : null;
|
|
177
|
+
const state = req.query['state'];
|
|
178
|
+
const cookieName = `openid.${providerName}.${state || ''}`;
|
|
179
|
+
const cookieValue = req.cookies[cookieName];
|
|
163
180
|
let tokenData;
|
|
164
181
|
try {
|
|
165
|
-
tokenData = jwt.verify(
|
|
182
|
+
tokenData = jwt.verify(cookieValue, env['SECRET'], {
|
|
166
183
|
issuer: 'directus',
|
|
167
184
|
});
|
|
168
185
|
}
|
|
169
186
|
catch (e) {
|
|
170
|
-
logger.warn(e, `[OpenID] Couldn't verify OpenID cookie`);
|
|
171
|
-
|
|
187
|
+
logger.warn(e, `[OpenID] Couldn't verify OpenID cookie ${state ? `for state ${state}` : ''}`);
|
|
188
|
+
const baseUrl = env['PUBLIC_URL'];
|
|
189
|
+
const loginPath = '/admin/login';
|
|
190
|
+
const url = new URL(loginPath, baseUrl);
|
|
191
|
+
const redirectTo = validRedirectUrl || url.toString();
|
|
192
|
+
return res.redirect(`${redirectTo}?reason=INVALID_CREDENTIALS`);
|
|
172
193
|
}
|
|
173
194
|
const { verifier, redirect, prompt } = tokenData;
|
|
174
195
|
const accountability = {
|
|
@@ -187,7 +208,7 @@ export function createOpenIDAuthRouter(providerName) {
|
|
|
187
208
|
});
|
|
188
209
|
let authResponse;
|
|
189
210
|
try {
|
|
190
|
-
res.clearCookie(
|
|
211
|
+
res.clearCookie(cookieName);
|
|
191
212
|
authResponse = await authenticationService.login(providerName, {
|
|
192
213
|
code: req.query['code'],
|
|
193
214
|
codeVerifier: verifier,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wbce-d9/api",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.1",
|
|
4
4
|
"description": "Directus is a real-time API and App dashboard for managing SQL database content",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -143,19 +143,19 @@
|
|
|
143
143
|
"uuid": "9.0.0",
|
|
144
144
|
"uuid-validate": "0.0.3",
|
|
145
145
|
"wellknown": "0.5.0",
|
|
146
|
+
"@wbce-d9/app": "9.33.8",
|
|
147
|
+
"@wbce-d9/constants": "10.0.0",
|
|
146
148
|
"@wbce-d9/exceptions": "10.0.0",
|
|
147
149
|
"@wbce-d9/extensions-sdk": "10.0.0",
|
|
148
|
-
"@wbce-d9/constants": "10.0.0",
|
|
149
150
|
"@wbce-d9/specs": "9.26.5",
|
|
150
151
|
"@wbce-d9/schema": "10.0.0",
|
|
151
|
-
"@wbce-d9/storage-driver-azure": "10.0.0",
|
|
152
152
|
"@wbce-d9/storage": "10.0.0",
|
|
153
|
+
"@wbce-d9/storage-driver-azure": "10.0.0",
|
|
153
154
|
"@wbce-d9/storage-driver-cloudinary": "10.0.0",
|
|
154
|
-
"@wbce-d9/app": "9.33.7",
|
|
155
155
|
"@wbce-d9/storage-driver-gcs": "10.0.0",
|
|
156
156
|
"@wbce-d9/storage-driver-local": "10.0.0",
|
|
157
|
-
"@wbce-d9/storage-driver-s3": "10.0.0",
|
|
158
157
|
"@wbce-d9/update-check": "10.0.0",
|
|
158
|
+
"@wbce-d9/storage-driver-s3": "10.0.0",
|
|
159
159
|
"@wbce-d9/utils": "10.0.0"
|
|
160
160
|
},
|
|
161
161
|
"devDependencies": {
|