@@ -81,8 +81,8 @@ export class AuthProviderOIDC implements AuthProvider {
8181 const state = randomState ( )
8282 const nonce = randomNonce ( )
8383
84- const supportsPKCE = config . serverMetadata ( ) . supportsPKCE ( )
85- const codeVerifier = supportsPKCE ? randomPKCECodeVerifier ( ) : undefined
84+ const isPKCEEnabled = this . isPKCEEnabled ( config )
85+ const codeVerifier = isPKCEEnabled ? randomPKCECodeVerifier ( ) : undefined
8686
8787 const authUrl = new URL ( config . serverMetadata ( ) . authorization_endpoint ! )
8888 authUrl . searchParams . set ( 'client_id' , this . oidcConfig . clientId ! )
@@ -91,7 +91,7 @@ export class AuthProviderOIDC implements AuthProvider {
9191 authUrl . searchParams . set ( 'scope' , this . oidcConfig . security . scope )
9292 authUrl . searchParams . set ( 'state' , state )
9393 authUrl . searchParams . set ( 'nonce' , nonce )
94- if ( supportsPKCE ) {
94+ if ( isPKCEEnabled ) {
9595 const codeChallenge = await calculatePKCECodeChallenge ( codeVerifier ! )
9696 authUrl . searchParams . set ( 'code_challenge' , codeChallenge )
9797 authUrl . searchParams . set ( 'code_challenge_method' , 'S256' )
@@ -108,15 +108,15 @@ export class AuthProviderOIDC implements AuthProvider {
108108 // Store state, nonce, and codeVerifier in httpOnly cookies (expires in 10 minutes)
109109 res . setCookie ( OAuthCookie . State , state , OAuthCookieSettings )
110110 res . setCookie ( OAuthCookie . Nonce , nonce , OAuthCookieSettings )
111- if ( supportsPKCE ) {
111+ if ( isPKCEEnabled ) {
112112 res . setCookie ( OAuthCookie . CodeVerifier , codeVerifier , OAuthCookieSettings )
113113 }
114114 return authUrl . toString ( )
115115 }
116116
117117 async handleCallback ( req : FastifyRequest , res : FastifyReply , query : Record < string , string > ) : Promise < UserModel > {
118118 const config = await this . getConfig ( )
119- const supportsPKCE = config . serverMetadata ( ) . supportsPKCE ( )
119+ const isPKCEEnabled = this . isPKCEEnabled ( config )
120120 const [ expectedState , expectedNonce , codeVerifier ] = [
121121 req . cookies [ OAuthCookie . State ] ,
122122 req . cookies [ OAuthCookie . Nonce ] ,
@@ -128,11 +128,11 @@ export class AuthProviderOIDC implements AuthProvider {
128128 throw new HttpException ( 'OAuth state is missing' , HttpStatus . BAD_REQUEST )
129129 }
130130
131- if ( supportsPKCE && ! codeVerifier ?. length ) {
131+ if ( isPKCEEnabled && ! codeVerifier ?. length ) {
132132 throw new HttpException ( 'OAuth code verifier is missing' , HttpStatus . BAD_REQUEST )
133133 }
134134
135- const pkceCodeVerifier = supportsPKCE ? codeVerifier : undefined
135+ const pkceCodeVerifier = isPKCEEnabled ? codeVerifier : undefined
136136 const callbackParams = new URLSearchParams ( query )
137137
138138 // Get Desktop Port if defined
@@ -275,6 +275,10 @@ export class AuthProviderOIDC implements AuthProvider {
275275 }
276276 }
277277
278+ private isPKCEEnabled ( config : Configuration ) : boolean {
279+ return ( this . oidcConfig . security . supportPKCE ?? true ) && config . serverMetadata ( ) . supportsPKCE ( )
280+ }
281+
278282 private async processUserInfo ( userInfo : UserInfoResponse , ip ?: string ) : Promise < UserModel > {
279283 // Extract user information
280284 const { login, email } = this . extractLoginAndEmail ( userInfo )
0 commit comments