|
3 | 3 | package oauth |
4 | 4 |
|
5 | 5 | import ( |
6 | | - "encoding/json" |
7 | 6 | "fmt" |
8 | 7 | "net/http" |
9 | 8 | "strings" |
10 | 9 |
|
11 | 10 | "github.com/github/github-mcp-server/pkg/http/headers" |
12 | 11 | "github.com/go-chi/chi/v5" |
| 12 | + "github.com/modelcontextprotocol/go-sdk/auth" |
13 | 13 | "github.com/modelcontextprotocol/go-sdk/oauthex" |
14 | 14 | ) |
15 | 15 |
|
@@ -95,34 +95,21 @@ func (h *AuthHandler) RegisterRoutes(r chi.Router) { |
95 | 95 |
|
96 | 96 | func (h *AuthHandler) metadataHandler() http.Handler { |
97 | 97 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
98 | | - // CORS headers for browser-based clients |
99 | | - w.Header().Set("Access-Control-Allow-Origin", "*") |
100 | | - w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS") |
101 | | - w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization") |
102 | | - |
103 | | - if r.Method == http.MethodOptions { |
104 | | - w.WriteHeader(http.StatusNoContent) |
105 | | - return |
106 | | - } |
107 | | - if r.Method != http.MethodGet { |
108 | | - w.WriteHeader(http.StatusMethodNotAllowed) |
109 | | - return |
110 | | - } |
111 | | - |
112 | 98 | resourcePath := resolveResourcePath( |
113 | 99 | strings.TrimPrefix(r.URL.Path, OAuthProtectedResourcePrefix), |
114 | 100 | h.cfg.ResourcePath, |
115 | 101 | ) |
116 | 102 | resourceURL := h.buildResourceURL(r, resourcePath) |
117 | 103 |
|
118 | | - w.Header().Set("Content-Type", "application/json") |
119 | | - _ = json.NewEncoder(w).Encode(&oauthex.ProtectedResourceMetadata{ |
| 104 | + metadata := &oauthex.ProtectedResourceMetadata{ |
120 | 105 | Resource: resourceURL, |
121 | 106 | AuthorizationServers: []string{h.cfg.AuthorizationServer}, |
122 | 107 | ResourceName: "GitHub MCP Server", |
123 | 108 | ScopesSupported: SupportedScopes, |
124 | 109 | BearerMethodsSupported: []string{"header"}, |
125 | | - }) |
| 110 | + } |
| 111 | + |
| 112 | + auth.ProtectedResourceMetadataHandler(metadata).ServeHTTP(w, r) |
126 | 113 | }) |
127 | 114 | } |
128 | 115 |
|
|
0 commit comments