@@ -177,7 +177,7 @@ export function callbackEventHandler({ onSuccess }: OAuthConfig<UserSession>) {
177
177
return sendRedirect (
178
178
event ,
179
179
consentUrl ,
180
- 200 ,
180
+ 302 ,
181
181
)
182
182
}
183
183
return oidcErrorHandler ( event , 'Token request failed' )
@@ -192,15 +192,20 @@ export function callbackEventHandler({ onSuccess }: OAuthConfig<UserSession>) {
192
192
if ( [ config . audience as string , config . clientId ] . some ( audience => accessToken . aud ?. includes ( audience ) || idToken ?. aud ?. includes ( audience ) ) && ( config . validateAccessToken || config . validateIdToken ) ) {
193
193
// Get OIDC configuration
194
194
const openIdConfiguration = ( config . openIdConfiguration && typeof config . openIdConfiguration === 'object' ) ? config . openIdConfiguration : typeof config . openIdConfiguration === 'string' ? await ofetch ( config . openIdConfiguration ) : await ( config . openIdConfiguration ! ) ( config )
195
- const validationOptions = { jwksUri : openIdConfiguration . jwks_uri as string , issuer : openIdConfiguration . issuer as string , ...config . audience && { audience : config . audience } }
196
-
197
- tokens = {
198
- accessToken : config . validateAccessToken ? await validateToken ( tokenResponse . access_token , validationOptions ) : accessToken ,
199
- ...tokenResponse . refresh_token && { refreshToken : tokenResponse . refresh_token } ,
200
- ...tokenResponse . id_token && { idToken : config . validateIdToken ? await validateToken ( tokenResponse . id_token , validationOptions ) : parseJwtToken ( tokenResponse . id_token ) } ,
195
+ const validationOptions = { jwksUri : openIdConfiguration . jwks_uri as string , issuer : openIdConfiguration . issuer as string , ...config . audience && { audience : [ config . audience , config . clientId ] } }
196
+ try {
197
+ tokens = {
198
+ accessToken : config . validateAccessToken ? await validateToken ( tokenResponse . access_token , validationOptions ) : accessToken ,
199
+ ...tokenResponse . refresh_token && { refreshToken : tokenResponse . refresh_token } ,
200
+ ...tokenResponse . id_token && { idToken : config . validateIdToken ? await validateToken ( tokenResponse . id_token , validationOptions ) : parseJwtToken ( tokenResponse . id_token ) } ,
201
+ }
202
+ }
203
+ catch ( error ) {
204
+ return oidcErrorHandler ( event , `[${ provider } ] Token validation failed: ${ error } ` )
201
205
}
202
206
}
203
207
else {
208
+ logger . info ( 'Skipped token validation' )
204
209
tokens = {
205
210
accessToken,
206
211
...tokenResponse . refresh_token && { refreshToken : tokenResponse . refresh_token } ,
@@ -278,7 +283,7 @@ export function logoutEventHandler({ onSuccess }: OAuthConfig<UserSession>) {
278
283
const logoutRedirectUri = logoutParams . logoutRedirectUri || config . logoutRedirectUri
279
284
280
285
// Set logout_hint and id_token_hint dynamic parameters if specified. According to https://openid.net/specs/openid-connect-rpinitiated-1_0.html#RPLogout
281
- const additionalLogoutParameters : Record < string , string > = config . additionalLogoutParameters || { }
286
+ const additionalLogoutParameters : Record < string , string > = config . additionalLogoutParameters ? { ... config . additionalLogoutParameters } : { }
282
287
if ( config . additionalLogoutParameters ) {
283
288
const userSession = await getUserSession ( event )
284
289
Object . keys ( config . additionalLogoutParameters ) . forEach ( ( key ) => {
0 commit comments