@@ -192,27 +192,30 @@ func (p *OAuthProxy) SetupRoutes(mux *http.ServeMux) {
192
192
log .Fatalf ("Failed to get provider: %v" , err )
193
193
}
194
194
195
- authorizeHandler := authorize .NewHandler (p .db , provider , p .metadata .ScopesSupported , p .GetOAuthClientID (), p .GetOAuthClientSecret ())
195
+ authorizeHandler := authorize .NewHandler (p .db , provider , p .metadata .ScopesSupported , p .GetOAuthClientID (), p .GetOAuthClientSecret (), p . config . RoutePrefix )
196
196
tokenHandler := token .NewHandler (p .db )
197
- callbackHandler := callback .NewHandler (p .db , provider , p .encryptionKey , p .GetOAuthClientID (), p .GetOAuthClientSecret (), p .mcpUIManager )
197
+ callbackHandler := callback .NewHandler (p .db , provider , p .encryptionKey , p .GetOAuthClientID (), p .GetOAuthClientSecret (), p .config . RoutePrefix , p . mcpUIManager )
198
198
revokeHandler := revoke .NewHandler (p .db )
199
199
tokenValidator := validate .NewTokenValidator (p .tokenManager , p .encryptionKey , p .db , provider , p .GetOAuthClientID (), p .GetOAuthClientSecret (), p .metadata .ScopesSupported )
200
200
201
- mux .HandleFunc ("GET /health" , p .withCORS (p .healthHandler ))
201
+ // Get route prefix from config
202
+ prefix := p .config .RoutePrefix
203
+
204
+ mux .HandleFunc ("GET " + prefix + "/health" , p .withCORS (p .healthHandler ))
202
205
203
206
// OAuth endpoints
204
- mux .HandleFunc ("GET /authorize" , p .withCORS (p .withRateLimit (authorizeHandler )))
205
- mux .HandleFunc ("GET /callback" , p .withCORS (p .withRateLimit (callbackHandler )))
206
- mux .HandleFunc ("POST /token" , p .withCORS (p .withRateLimit (tokenHandler )))
207
- mux .HandleFunc ("POST /revoke" , p .withCORS (p .withRateLimit (revokeHandler )))
208
- mux .HandleFunc ("POST /register" , p .withCORS (p .withRateLimit (register .NewHandler (p .db ))))
207
+ mux .HandleFunc ("GET " + prefix + " /authorize" , p .withCORS (p .withRateLimit (authorizeHandler )))
208
+ mux .HandleFunc ("GET " + prefix + " /callback" , p .withCORS (p .withRateLimit (callbackHandler )))
209
+ mux .HandleFunc ("POST " + prefix + " /token" , p .withCORS (p .withRateLimit (tokenHandler )))
210
+ mux .HandleFunc ("POST " + prefix + " /revoke" , p .withCORS (p .withRateLimit (revokeHandler )))
211
+ mux .HandleFunc ("POST " + prefix + " /register" , p .withCORS (p .withRateLimit (register .NewHandler (p .db ))))
209
212
210
213
// Metadata endpoints
211
214
mux .HandleFunc ("GET /.well-known/oauth-authorization-server" , p .withCORS (p .oauthMetadataHandler ))
212
215
mux .HandleFunc ("GET /.well-known/oauth-protected-resource" , p .withCORS (p .protectedResourceMetadataHandler ))
213
216
214
217
// Protect everything else
215
- mux .HandleFunc ("/{path...}" , p .withCORS (p .withRateLimit (tokenValidator .WithTokenValidation (p .mcpProxyHandler ))))
218
+ mux .HandleFunc (prefix + "/{path...}" , p .withCORS (p .withRateLimit (tokenValidator .WithTokenValidation (p .mcpProxyHandler ))))
216
219
}
217
220
218
221
// GetHandler returns an http.Handler for the OAuth proxy
@@ -270,21 +273,22 @@ func (p *OAuthProxy) healthHandler(w http.ResponseWriter, r *http.Request) {
270
273
271
274
func (p * OAuthProxy ) oauthMetadataHandler (w http.ResponseWriter , r * http.Request ) {
272
275
baseURL := handlerutils .GetBaseURL (r )
276
+ prefix := p .config .RoutePrefix
273
277
274
278
// Create dynamic metadata based on the request
275
279
metadata := & types.OAuthMetadata {
276
280
Issuer : baseURL ,
277
281
ServiceDocumentation : p .metadata .ServiceDocumentation ,
278
- AuthorizationEndpoint : fmt .Sprintf ("%s/authorize" , baseURL ),
282
+ AuthorizationEndpoint : fmt .Sprintf ("%s%s /authorize" , baseURL , prefix ),
279
283
ResponseTypesSupported : p .metadata .ResponseTypesSupported ,
280
284
CodeChallengeMethodsSupported : p .metadata .CodeChallengeMethodsSupported ,
281
- TokenEndpoint : fmt .Sprintf ("%s/token" , baseURL ),
285
+ TokenEndpoint : fmt .Sprintf ("%s%s /token" , baseURL , prefix ),
282
286
TokenEndpointAuthMethodsSupported : p .metadata .TokenEndpointAuthMethodsSupported ,
283
287
GrantTypesSupported : p .metadata .GrantTypesSupported ,
284
288
ScopesSupported : p .metadata .ScopesSupported ,
285
- RevocationEndpoint : fmt .Sprintf ("%s/revoke" , baseURL ),
289
+ RevocationEndpoint : fmt .Sprintf ("%s%s /revoke" , baseURL , prefix ),
286
290
RevocationEndpointAuthMethodsSupported : p .metadata .RevocationEndpointAuthMethodsSupported ,
287
- RegistrationEndpoint : fmt .Sprintf ("%s/register" , baseURL ),
291
+ RegistrationEndpoint : fmt .Sprintf ("%s%s /register" , baseURL , prefix ),
288
292
RegistrationEndpointAuthMethodsSupported : p .metadata .RegistrationEndpointAuthMethodsSupported ,
289
293
}
290
294
@@ -293,9 +297,12 @@ func (p *OAuthProxy) oauthMetadataHandler(w http.ResponseWriter, r *http.Request
293
297
294
298
func (p * OAuthProxy ) protectedResourceMetadataHandler (w http.ResponseWriter , r * http.Request ) {
295
299
baseURL := handlerutils .GetBaseURL (r )
300
+ prefix := p .config .RoutePrefix
301
+ resourceURL := baseURL + prefix
302
+
296
303
metadata := types.OAuthProtectedResourceMetadata {
297
- Resource : baseURL ,
298
- AuthorizationServers : []string {baseURL },
304
+ Resource : resourceURL ,
305
+ AuthorizationServers : []string {baseURL + prefix },
299
306
Scopes : p .metadata .ScopesSupported ,
300
307
ResourceName : p .resourceName ,
301
308
ResourceDocumentation : p .metadata .ServiceDocumentation ,
0 commit comments