Merge pull request #1023 from trheyi/main
Refactor OAuth endpoint structure and add well-known handlers
This commit is contained in:
commit
35dd8b5017
3 changed files with 31 additions and 25 deletions
|
|
@ -56,20 +56,6 @@ func (openapi *OpenAPI) attachOAuth(base *gin.RouterGroup) {
|
||||||
// Token Exchange - RFC 8693
|
// Token Exchange - RFC 8693
|
||||||
oauth.POST("/token_exchange", openapi.oauthTokenExchange)
|
oauth.POST("/token_exchange", openapi.oauthTokenExchange)
|
||||||
|
|
||||||
// OAuth Discovery and Metadata Endpoints
|
|
||||||
// IMPORTANT: These should be at the root level for proper MCP discovery
|
|
||||||
// If base is /v1, consider mounting these at the application root instead
|
|
||||||
wellKnown := base.Group("/.well-known")
|
|
||||||
|
|
||||||
// OAuth Authorization Server Metadata - RFC 8414 (Required by MCP)
|
|
||||||
wellKnown.GET("/oauth-authorization-server", openapi.oauthServerMetadata)
|
|
||||||
|
|
||||||
// OpenID Connect Discovery - OpenID Connect Discovery 1.0
|
|
||||||
wellKnown.GET("/openid_configuration", openapi.oauthOpenIDConfiguration)
|
|
||||||
|
|
||||||
// OAuth Protected Resource Metadata - RFC 9728 (Required by MCP)
|
|
||||||
wellKnown.GET("/oauth-protected-resource", openapi.oauthProtectedResourceMetadata)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// OAuth Core Endpoints Implementation
|
// OAuth Core Endpoints Implementation
|
||||||
|
|
@ -114,14 +100,3 @@ func (openapi *OpenAPI) oauthPushedAuthorizationRequest(c *gin.Context) {}
|
||||||
|
|
||||||
// oauthTokenExchange handles token exchange - RFC 8693
|
// oauthTokenExchange handles token exchange - RFC 8693
|
||||||
func (openapi *OpenAPI) oauthTokenExchange(c *gin.Context) {}
|
func (openapi *OpenAPI) oauthTokenExchange(c *gin.Context) {}
|
||||||
|
|
||||||
// OAuth Discovery and Metadata Endpoints Implementation
|
|
||||||
|
|
||||||
// oauthServerMetadata returns authorization server metadata - RFC 8414
|
|
||||||
func (openapi *OpenAPI) oauthServerMetadata(c *gin.Context) {}
|
|
||||||
|
|
||||||
// oauthOpenIDConfiguration returns OpenID Connect configuration
|
|
||||||
func (openapi *OpenAPI) oauthOpenIDConfiguration(c *gin.Context) {}
|
|
||||||
|
|
||||||
// oauthProtectedResourceMetadata returns protected resource metadata - RFC 9728
|
|
||||||
func (openapi *OpenAPI) oauthProtectedResourceMetadata(c *gin.Context) {}
|
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,9 @@ func (openapi *OpenAPI) Attach(router *gin.Engine) {
|
||||||
baseURL := openapi.Config.BaseURL
|
baseURL := openapi.Config.BaseURL
|
||||||
group := router.Group(baseURL)
|
group := router.Group(baseURL)
|
||||||
|
|
||||||
|
// Well-known handlers
|
||||||
|
openapi.attachWellKnown(router)
|
||||||
|
|
||||||
// OAuth handlers
|
// OAuth handlers
|
||||||
openapi.attachOAuth(group)
|
openapi.attachOAuth(group)
|
||||||
|
|
||||||
|
|
|
||||||
28
openapi/well-known.go
Normal file
28
openapi/well-known.go
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
package openapi
|
||||||
|
|
||||||
|
import "github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
// attachWellKnown attaches the well-known handlers to the router
|
||||||
|
func (openapi *OpenAPI) attachWellKnown(router *gin.Engine) {
|
||||||
|
|
||||||
|
// OAuth Discovery and Metadata Endpoints
|
||||||
|
wellKnown := router.Group("/.well-known")
|
||||||
|
|
||||||
|
// OAuth Authorization Server Metadata - RFC 8414 (Required by MCP)
|
||||||
|
wellKnown.GET("/oauth-authorization-server", openapi.oauthServerMetadata)
|
||||||
|
|
||||||
|
// OpenID Connect Discovery - OpenID Connect Discovery 1.0
|
||||||
|
wellKnown.GET("/openid_configuration", openapi.oauthOpenIDConfiguration)
|
||||||
|
|
||||||
|
// OAuth Protected Resource Metadata - RFC 9728 (Required by MCP)
|
||||||
|
wellKnown.GET("/oauth-protected-resource", openapi.oauthProtectedResourceMetadata)
|
||||||
|
}
|
||||||
|
|
||||||
|
// oauthServerMetadata returns authorization server metadata - RFC 8414
|
||||||
|
func (openapi *OpenAPI) oauthServerMetadata(c *gin.Context) {}
|
||||||
|
|
||||||
|
// oauthOpenIDConfiguration returns OpenID Connect configuration
|
||||||
|
func (openapi *OpenAPI) oauthOpenIDConfiguration(c *gin.Context) {}
|
||||||
|
|
||||||
|
// oauthProtectedResourceMetadata returns protected resource metadata - RFC 9728
|
||||||
|
func (openapi *OpenAPI) oauthProtectedResourceMetadata(c *gin.Context) {}
|
||||||
Loading…
Add table
Reference in a new issue