Skip to content

Commit e616287

Browse files
tobyreiddygeenenSteven Hollingsworth
authored
fix(openIDConnect scheme): Check token expiration before id_token (#1684)
* fix(openIDConnect scheme): Check token expiration before id_token During an Axios call, the token is not automatically refreshed because it relies on the tokenExpired return of the scheme check function, which first checks id_token which often expires at the same time, and therefore does not detect any problems. By checking first the token expiration before the id_token, the problem is solved Related issue : #1370 * Fix linting error * Added comment explaining the order / reasoning #1684 (comment) * Adjusted comment to be clearer about the exact order * One more comment edit * Fixing linting error (again) * Fix linting error Check failure on line 122 in src/schemes/openIDConnect.ts Co-authored-by: Dylan Geenen <58949478+dygeenen@users.noreply.github.com> Co-authored-by: Steven Hollingsworth <shollingsworth@barracuda.com>
1 parent 532b3d6 commit e616287

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/schemes/openIDConnect.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,30 @@ export class OpenIDConnectScheme<
113113
return response
114114
}
115115

116-
// Id token has expired. Force reset.
117-
if (idTokenStatus.expired()) {
118-
response.idTokenExpired = true
119-
return response
120-
}
121-
122116
// Token has expired, Force reset.
123117
if (tokenStatus.expired()) {
124118
response.tokenExpired = true
125119
return response
126120
}
127121

122+
/**
123+
Id token has expired. Force reset.
124+
125+
idToken needs to be set after token because the access_token
126+
is sent in the Authorization header when making an axios request. If
127+
the access_token is expired, we need to refresh that token before
128+
continuing.
129+
130+
Checking whether the id_token has expired doesn't guarantee a successful
131+
call to the (a) back end and typically the id_token has a different
132+
(shorter) expiry schedule to the access_token.
133+
*/
134+
135+
if (idTokenStatus.expired()) {
136+
response.idTokenExpired = true
137+
return response
138+
}
139+
128140
response.valid = true
129141
return response
130142
}

0 commit comments

Comments
 (0)