@@ -192,27 +192,30 @@ func (p *OAuthProxy) SetupRoutes(mux *http.ServeMux) {
192192 log .Fatalf ("Failed to get provider: %v" , err )
193193 }
194194
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 )
196196 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 )
198198 revokeHandler := revoke .NewHandler (p .db )
199199 tokenValidator := validate .NewTokenValidator (p .tokenManager , p .encryptionKey , p .db , provider , p .GetOAuthClientID (), p .GetOAuthClientSecret (), p .metadata .ScopesSupported )
200200
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 ))
202205
203206 // 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 ))))
209212
210213 // Metadata endpoints
211214 mux .HandleFunc ("GET /.well-known/oauth-authorization-server" , p .withCORS (p .oauthMetadataHandler ))
212215 mux .HandleFunc ("GET /.well-known/oauth-protected-resource" , p .withCORS (p .protectedResourceMetadataHandler ))
213216
214217 // 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 ))))
216219}
217220
218221// GetHandler returns an http.Handler for the OAuth proxy
@@ -270,21 +273,22 @@ func (p *OAuthProxy) healthHandler(w http.ResponseWriter, r *http.Request) {
270273
271274func (p * OAuthProxy ) oauthMetadataHandler (w http.ResponseWriter , r * http.Request ) {
272275 baseURL := handlerutils .GetBaseURL (r )
276+ prefix := p .config .RoutePrefix
273277
274278 // Create dynamic metadata based on the request
275279 metadata := & types.OAuthMetadata {
276280 Issuer : baseURL ,
277281 ServiceDocumentation : p .metadata .ServiceDocumentation ,
278- AuthorizationEndpoint : fmt .Sprintf ("%s/authorize" , baseURL ),
282+ AuthorizationEndpoint : fmt .Sprintf ("%s%s /authorize" , baseURL , prefix ),
279283 ResponseTypesSupported : p .metadata .ResponseTypesSupported ,
280284 CodeChallengeMethodsSupported : p .metadata .CodeChallengeMethodsSupported ,
281- TokenEndpoint : fmt .Sprintf ("%s/token" , baseURL ),
285+ TokenEndpoint : fmt .Sprintf ("%s%s /token" , baseURL , prefix ),
282286 TokenEndpointAuthMethodsSupported : p .metadata .TokenEndpointAuthMethodsSupported ,
283287 GrantTypesSupported : p .metadata .GrantTypesSupported ,
284288 ScopesSupported : p .metadata .ScopesSupported ,
285- RevocationEndpoint : fmt .Sprintf ("%s/revoke" , baseURL ),
289+ RevocationEndpoint : fmt .Sprintf ("%s%s /revoke" , baseURL , prefix ),
286290 RevocationEndpointAuthMethodsSupported : p .metadata .RevocationEndpointAuthMethodsSupported ,
287- RegistrationEndpoint : fmt .Sprintf ("%s/register" , baseURL ),
291+ RegistrationEndpoint : fmt .Sprintf ("%s%s /register" , baseURL , prefix ),
288292 RegistrationEndpointAuthMethodsSupported : p .metadata .RegistrationEndpointAuthMethodsSupported ,
289293 }
290294
@@ -293,9 +297,12 @@ func (p *OAuthProxy) oauthMetadataHandler(w http.ResponseWriter, r *http.Request
293297
294298func (p * OAuthProxy ) protectedResourceMetadataHandler (w http.ResponseWriter , r * http.Request ) {
295299 baseURL := handlerutils .GetBaseURL (r )
300+ prefix := p .config .RoutePrefix
301+ resourceURL := baseURL + prefix
302+
296303 metadata := types.OAuthProtectedResourceMetadata {
297- Resource : baseURL ,
298- AuthorizationServers : []string {baseURL },
304+ Resource : resourceURL ,
305+ AuthorizationServers : []string {baseURL + prefix },
299306 Scopes : p .metadata .ScopesSupported ,
300307 ResourceName : p .resourceName ,
301308 ResourceDocumentation : p .metadata .ServiceDocumentation ,
0 commit comments