Skip to content

Commit 11f118b

Browse files
authored
Fix OIDC integration failing for some auth providers (#911)
* Fix OIDC integration failing for some auth providers * Add changeset
1 parent fcd2710 commit 11f118b

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

.changeset/itchy-otters-smile.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/integration-oidc': patch
3+
---
4+
5+
Fix OIDC integration failing for some auth providers

integrations/oidc/src/index.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -300,28 +300,28 @@ const handleFetchEvent: FetchEventCallback<OIDCRuntimeContext> = async (request,
300300
redirect_uri: `${installationURL}/visitor-auth/response`,
301301
});
302302

303-
const accessTokenResp = await fetch(accessTokenEndpoint, {
303+
const tokenResp = await fetch(accessTokenEndpoint, {
304304
method: 'POST',
305305
headers: { 'content-type': 'application/x-www-form-urlencoded' },
306306
body: searchParams,
307307
});
308308

309-
if (!accessTokenResp.ok) {
309+
if (!tokenResp.ok) {
310310
return new Response(
311-
'Error: Could not fetch access token from your authentication provider',
311+
'Error: Could not fetch ID token from your authentication provider',
312312
{
313313
status: 401,
314314
},
315315
);
316316
}
317317

318-
const accessTokenData = await accessTokenResp.json<OIDCTokenResponseData>();
319-
if (!accessTokenData.access_token) {
320-
logger.debug(JSON.stringify(accessTokenResp, null, 2));
318+
const tokenRespData = await tokenResp.json<OIDCTokenResponseData>();
319+
if (!tokenRespData.id_token) {
320+
logger.debug(JSON.stringify(tokenResp, null, 2));
321321
logger.debug(
322-
`Did not receive access token. Error: ${accessTokenResp && 'error' in accessTokenResp ? accessTokenResp.error : ''} ${
323-
accessTokenResp && 'error_description' in accessTokenResp
324-
? accessTokenResp.error_description
322+
`Did not receive access token. Error: ${tokenResp && 'error' in tokenResp ? tokenResp.error : ''} ${
323+
tokenResp && 'error_description' in tokenResp
324+
? tokenResp.error_description
325325
: ''
326326
}`,
327327
);
@@ -334,7 +334,7 @@ const handleFetchEvent: FetchEventCallback<OIDCRuntimeContext> = async (request,
334334
}
335335

336336
// TODO: verify token using JWKS and check audience (aud) claims
337-
const decodedAccessToken = await jwt.decode(accessTokenData.access_token);
337+
const decodedIdToken = await jwt.decode(tokenRespData.id_token);
338338
const privateKey = context.environment.signingSecrets.siteInstallation;
339339
if (!privateKey) {
340340
return new Response('Error: Missing private key from site installation', {
@@ -346,7 +346,7 @@ const handleFetchEvent: FetchEventCallback<OIDCRuntimeContext> = async (request,
346346
try {
347347
jwtToken = await jwt.sign(
348348
{
349-
...(decodedAccessToken.payload ?? {}),
349+
...(decodedIdToken.payload ?? {}),
350350
exp: Math.floor(Date.now() / 1000) + 1 * (60 * 60),
351351
},
352352
privateKey,

0 commit comments

Comments
 (0)