Skip to content

Commit 09f1200

Browse files
committed
fix(ADAPT): use JWT webhook auth
1 parent 4ef21c6 commit 09f1200

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

server/controllers/AuthController.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,12 @@ export class AuthController {
519519
console.error('Error creating default user applications!', e);
520520
}
521521

522-
await this._notifyConductorOfNewUser(foundUser);
523-
await this._notifyADAPTOfNewUser(foundUser);
522+
const webhookPromises = [
523+
this._notifyConductorOfNewUser(foundUser),
524+
this._notifyADAPTOfNewUser(foundUser)
525+
];
526+
527+
await Promise.all(webhookPromises); // both return false and log if failed, so they shouldn't affect each other
524528

525529
let shouldCreateSSOSession = true;
526530
let redirectCASService = null;
@@ -1155,11 +1159,14 @@ export class AuthController {
11551159
}
11561160
}
11571161

1158-
private _getADAPTWebhookHeaders() {
1162+
private async _getADAPTWebhookHeaders() {
1163+
const encoded = new TextEncoder().encode(process.env.ADAPT_API_KEY ?? 'unknown');
1164+
const jwtToSend = await new SignJWT({}).setProtectedHeader({ alg: 'HS256', typ: 'JWT' }).setIssuedAt().setExpirationTime('1h').sign(encoded);
1165+
11591166
return {
11601167
'Content-Type': 'application/json',
11611168
'X-Requested-With': 'XMLHttpRequest',
1162-
'Authorization': `Bearer ${process.env.ADAPT_API_KEY}`,
1169+
'Authorization': `Bearer ${jwtToSend}`,
11631170
'Origin': process.env.PRODUCTION_DOMAIN ?? process.env.DOMAIN ?? 'one.libretexts.org',
11641171
};
11651172
}
@@ -1183,7 +1190,7 @@ export class AuthController {
11831190
};
11841191

11851192
const res = await axios.post(adaptWebhookURL, payload, {
1186-
headers: this._getADAPTWebhookHeaders(),
1193+
headers: await this._getADAPTWebhookHeaders(),
11871194
});
11881195

11891196
if (res.data.err) {
@@ -1211,7 +1218,7 @@ export class AuthController {
12111218
};
12121219

12131220
const res = await axios.post(adaptWebhookURL, payload, {
1214-
headers: this._getADAPTWebhookHeaders(),
1221+
headers: await this._getADAPTWebhookHeaders(),
12151222
});
12161223

12171224
if (res.data.err) {

server/controllers/VerificationRequestController.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,12 @@ export class VerificationRequestController {
255255

256256
// Notify conductor of verification update
257257
const authController = new AuthController();
258-
await authController.notifyConductorOfVerificationUpdate(foundUser);
259-
await authController.notifyADAPTOfVerificationUpdate(foundUser);
258+
const webhookPromises = [
259+
authController.notifyConductorOfVerificationUpdate(foundUser),
260+
authController.notifyADAPTOfVerificationUpdate(foundUser)
261+
];
262+
263+
await Promise.all(webhookPromises); // Both calls return false and log if failed, so one shouldn't affect the other
260264

261265
// Generate ADAPT access code if it was requested (and approved)
262266
const foundADAPTApp = approvedApps.find((a) => a.get('name') === 'ADAPT');

0 commit comments

Comments
 (0)