@@ -158,13 +158,15 @@ export class OAuth2Service extends EventEmitter {
158158 private openidConfigurationHandler : RequestHandler = ( _req , res ) => {
159159 assertIsString ( this . issuer . url , 'Unknown issuer url.' ) ;
160160
161+ const normalizedIssuerUrl = trimPotentialTrailingSlash ( this . issuer . url ) ;
162+
161163 const openidConfig = {
162164 issuer : this . issuer . url ,
163- token_endpoint : `${ this . issuer . url } ${ this . #endpoints. token } ` ,
164- authorization_endpoint : `${ this . issuer . url } ${ this . #endpoints. authorize } ` ,
165- userinfo_endpoint : `${ this . issuer . url } ${ this . #endpoints. userinfo } ` ,
165+ token_endpoint : `${ normalizedIssuerUrl } ${ this . #endpoints. token } ` ,
166+ authorization_endpoint : `${ normalizedIssuerUrl } ${ this . #endpoints. authorize } ` ,
167+ userinfo_endpoint : `${ normalizedIssuerUrl } ${ this . #endpoints. userinfo } ` ,
166168 token_endpoint_auth_methods_supported : [ 'none' ] ,
167- jwks_uri : `${ this . issuer . url } ${ this . #endpoints. jwks } ` ,
169+ jwks_uri : `${ normalizedIssuerUrl } ${ this . #endpoints. jwks } ` ,
168170 response_types_supported : [ 'code' ] ,
169171 grant_types_supported : [
170172 'client_credentials' ,
@@ -174,10 +176,10 @@ export class OAuth2Service extends EventEmitter {
174176 token_endpoint_auth_signing_alg_values_supported : [ 'RS256' ] ,
175177 response_modes_supported : [ 'query' ] ,
176178 id_token_signing_alg_values_supported : [ 'RS256' ] ,
177- revocation_endpoint : `${ this . issuer . url } ${ this . #endpoints. revoke } ` ,
179+ revocation_endpoint : `${ normalizedIssuerUrl } ${ this . #endpoints. revoke } ` ,
178180 subject_types_supported : [ 'public' ] ,
179- end_session_endpoint : `${ this . issuer . url } ${ this . #endpoints. endSession } ` ,
180- introspection_endpoint : `${ this . issuer . url } ${ this . #endpoints. introspect } ` ,
181+ end_session_endpoint : `${ normalizedIssuerUrl } ${ this . #endpoints. endSession } ` ,
182+ introspection_endpoint : `${ normalizedIssuerUrl } ${ this . #endpoints. introspect } ` ,
181183 code_challenge_methods_supported : supportedPkceAlgorithms ,
182184 } ;
183185
@@ -192,10 +194,7 @@ export class OAuth2Service extends EventEmitter {
192194 try {
193195 const tokenTtl = defaultTokenTtl ;
194196
195- res . set ( {
196- 'Cache-Control' : 'no-store' ,
197- Pragma : 'no-cache' ,
198- } ) ;
197+ res . set ( { 'Cache-Control' : 'no-store' , Pragma : 'no-cache' } ) ;
199198
200199 let xfn : ScopesOrTransform | undefined ;
201200
@@ -207,9 +206,7 @@ export class OAuth2Service extends EventEmitter {
207206 const verifier = req . body [ 'code_verifier' ] ;
208207 const savedCodeChallenge = this . #codeChallenges. get ( code ) ;
209208 if ( savedCodeChallenge === undefined ) {
210- throw new AssertionError ( {
211- message : 'code_challenge required' ,
212- } ) ;
209+ throw new AssertionError ( { message : 'code_challenge required' } ) ;
213210 }
214211 this . #codeChallenges. delete ( code ) ;
215212 if ( ! isValidPkceCodeVerifier ( verifier ) ) {
@@ -256,27 +253,17 @@ export class OAuth2Service extends EventEmitter {
256253 case 'authorization_code' :
257254 scope = scope ?? 'dummy' ;
258255 xfn = ( _header , payload ) => {
259- Object . assign ( payload , {
260- sub : 'johndoe' ,
261- amr : [ 'pwd' ] ,
262- scope,
263- } ) ;
256+ Object . assign ( payload , { sub : 'johndoe' , amr : [ 'pwd' ] , scope } ) ;
264257 } ;
265258 break ;
266259 case 'refresh_token' :
267260 scope = scope ?? 'dummy' ;
268261 xfn = ( _header , payload ) => {
269- Object . assign ( payload , {
270- sub : 'johndoe' ,
271- amr : [ 'pwd' ] ,
272- scope,
273- } ) ;
262+ Object . assign ( payload , { sub : 'johndoe' , amr : [ 'pwd' ] , scope } ) ;
274263 } ;
275264 break ;
276265 default :
277- return res . status ( 400 ) . json ( {
278- error : 'invalid_grant' ,
279- } ) ;
266+ return res . status ( 400 ) . json ( { error : 'invalid_grant' } ) ;
280267 }
281268
282269 const token = await this . buildToken ( req , tokenTtl , xfn ) ;
@@ -292,14 +279,9 @@ export class OAuth2Service extends EventEmitter {
292279 const clientId = credentials ? credentials . name : req . body . client_id ;
293280
294281 const xfn : JwtTransform = ( _header , payload ) => {
295- Object . assign ( payload , {
296- sub : 'johndoe' ,
297- aud : clientId ,
298- } ) ;
282+ Object . assign ( payload , { sub : 'johndoe' , aud : clientId } ) ;
299283 if ( reqBody . code !== undefined && this . #nonce[ reqBody . code ] ) {
300- Object . assign ( payload , {
301- nonce : this . #nonce[ reqBody . code ] ,
302- } ) ;
284+ Object . assign ( payload , { nonce : this . #nonce[ reqBody . code ] } ) ;
303285 delete this . #nonce[ reqBody . code ] ;
304286 }
305287 } ;
@@ -308,10 +290,7 @@ export class OAuth2Service extends EventEmitter {
308290 body [ 'refresh_token' ] = randomUUID ( ) ;
309291 }
310292
311- const tokenEndpointResponse : MutableResponse = {
312- body,
313- statusCode : 200 ,
314- } ;
293+ const tokenEndpointResponse : MutableResponse = { body, statusCode : 200 } ;
315294
316295 /**
317296 * Before token response event.
@@ -417,9 +396,7 @@ export class OAuth2Service extends EventEmitter {
417396
418397 private userInfoHandler : RequestHandler = ( req , res ) => {
419398 const userInfoResponse : MutableResponse = {
420- body : {
421- sub : 'johndoe' ,
422- } ,
399+ body : { sub : 'johndoe' } ,
423400 statusCode : 200 ,
424401 } ;
425402
@@ -435,9 +412,7 @@ export class OAuth2Service extends EventEmitter {
435412 } ;
436413
437414 private revokeHandler : RequestHandler = ( req , res ) => {
438- const revokeResponse : StatusCodeMutableResponse = {
439- statusCode : 200 ,
440- } ;
415+ const revokeResponse : StatusCodeMutableResponse = { statusCode : 200 } ;
441416
442417 /**
443418 * Before revoke event.
@@ -473,9 +448,7 @@ export class OAuth2Service extends EventEmitter {
473448
474449 private introspectHandler : RequestHandler = ( req , res ) => {
475450 const introspectResponse : MutableResponse = {
476- body : {
477- active : true ,
478- } ,
451+ body : { active : true } ,
479452 statusCode : 200 ,
480453 } ;
481454
@@ -492,3 +465,7 @@ export class OAuth2Service extends EventEmitter {
492465 . json ( introspectResponse . body ) ;
493466 } ;
494467}
468+
469+ const trimPotentialTrailingSlash = ( url : string ) : string => {
470+ return url . endsWith ( '/' ) ? url . slice ( 0 , - 1 ) : url ;
471+ } ;
0 commit comments