@@ -6,6 +6,7 @@ export interface AuthServerOptions {
66 metadataPath ?: string ;
77 isOpenIdConfiguration ?: boolean ;
88 loggingEnabled ?: boolean ;
9+ routePrefix ?: string ;
910}
1011
1112export function createAuthServer (
@@ -16,8 +17,16 @@ export function createAuthServer(
1617 const {
1718 metadataPath = '/.well-known/oauth-authorization-server' ,
1819 isOpenIdConfiguration = false ,
19- loggingEnabled = true
20+ loggingEnabled = true ,
21+ routePrefix = ''
2022 } = options ;
23+
24+ const authRoutes = {
25+ authorization_endpoint : `${ routePrefix } /authorize` ,
26+ token_endpoint : `${ routePrefix } /token` ,
27+ registration_endpoint : `${ routePrefix } /register`
28+ } ;
29+
2130 const app = express ( ) ;
2231 app . use ( express . json ( ) ) ;
2332 app . use ( express . urlencoded ( { extended : true } ) ) ;
@@ -52,9 +61,9 @@ export function createAuthServer(
5261
5362 const metadata : any = {
5463 issuer : getAuthBaseUrl ( ) ,
55- authorization_endpoint : `${ getAuthBaseUrl ( ) } /authorize ` ,
56- token_endpoint : `${ getAuthBaseUrl ( ) } /token ` ,
57- registration_endpoint : `${ getAuthBaseUrl ( ) } /register ` ,
64+ authorization_endpoint : `${ getAuthBaseUrl ( ) } ${ authRoutes . authorization_endpoint } ` ,
65+ token_endpoint : `${ getAuthBaseUrl ( ) } ${ authRoutes . token_endpoint } ` ,
66+ registration_endpoint : `${ getAuthBaseUrl ( ) } ${ authRoutes . registration_endpoint } ` ,
5867 response_types_supported : [ 'code' ] ,
5968 grant_types_supported : [ 'authorization_code' , 'refresh_token' ] ,
6069 code_challenge_methods_supported : [ 'S256' ] ,
@@ -71,7 +80,7 @@ export function createAuthServer(
7180 res . json ( metadata ) ;
7281 } ) ;
7382
74- app . get ( '/authorize' , ( req : Request , res : Response ) => {
83+ app . get ( authRoutes . authorization_endpoint , ( req : Request , res : Response ) => {
7584 checks . push ( {
7685 id : 'authorization-request' ,
7786 name : 'AuthorizationRequest' ,
@@ -105,7 +114,7 @@ export function createAuthServer(
105114 res . redirect ( redirectUrl . toString ( ) ) ;
106115 } ) ;
107116
108- app . post ( '/token' , ( req : Request , res : Response ) => {
117+ app . post ( authRoutes . token_endpoint , ( req : Request , res : Response ) => {
109118 checks . push ( {
110119 id : 'token-request' ,
111120 name : 'TokenRequest' ,
@@ -131,7 +140,7 @@ export function createAuthServer(
131140 } ) ;
132141 } ) ;
133142
134- app . post ( '/register' , ( req : Request , res : Response ) => {
143+ app . post ( authRoutes . registration_endpoint , ( req : Request , res : Response ) => {
135144 checks . push ( {
136145 id : 'client-registration' ,
137146 name : 'ClientRegistration' ,
0 commit comments