Skip to content

Commit e2f432d

Browse files
authored
Update extract access token for github mcpmark server (#1318)
1 parent 8a0f803 commit e2f432d

File tree

1 file changed

+17
-29
lines changed
  • mcp_servers/github_mcpmark/internal/ghmcp

1 file changed

+17
-29
lines changed

mcp_servers/github_mcpmark/internal/ghmcp/server.go

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -593,42 +593,30 @@ func newHTTPMCPServer(cfg MCPServerConfig) (*server.MCPServer, error) {
593593

594594
// extractTokenFromRequest extracts the GitHub token from an HTTP request.
595595
// It tries, in order:
596-
// 1. Authorization: Bearer <token> header
596+
// 1. AUTH_DATA environment variable (plain JSON with "access_token" field)
597597
// 2. x-auth-data header (base64-encoded JSON with "access_token" field)
598-
// 3. AUTH_DATA environment variable (plain JSON with "access_token" field)
599598
func extractTokenFromRequest(r *http.Request) string {
600-
// 1. Authorization: Bearer <token>
601-
if auth := r.Header.Get("Authorization"); auth != "" {
602-
if parts := strings.SplitN(auth, " ", 2); len(parts) == 2 && strings.EqualFold(parts[0], "Bearer") {
603-
if token := strings.TrimSpace(parts[1]); token != "" {
604-
return token
599+
// AUTH_DATA env var (plain JSON) then x-auth-data header (base64-encoded JSON).
600+
// Resolve the raw JSON string first, then parse once.
601+
authData := os.Getenv("AUTH_DATA")
602+
if authData == "" {
603+
if headerVal := r.Header.Get("x-auth-data"); headerVal != "" {
604+
decoded, err := base64.StdEncoding.DecodeString(headerVal)
605+
if err != nil {
606+
return ""
605607
}
608+
authData = string(decoded)
606609
}
607610
}
608-
609-
// 2. x-auth-data header (base64-encoded JSON)
610-
if headerVal := r.Header.Get("x-auth-data"); headerVal != "" {
611-
if decoded, err := base64.StdEncoding.DecodeString(headerVal); err == nil {
612-
var data map[string]interface{}
613-
if json.Unmarshal(decoded, &data) == nil {
614-
if token, ok := data["access_token"].(string); ok && token != "" {
615-
return token
616-
}
617-
}
618-
}
611+
if authData == "" {
612+
return ""
619613
}
620-
621-
// 3. AUTH_DATA env var (plain JSON)
622-
if authData := os.Getenv("AUTH_DATA"); authData != "" {
623-
var data map[string]interface{}
624-
if json.Unmarshal([]byte(authData), &data) == nil {
625-
if token, ok := data["access_token"].(string); ok && token != "" {
626-
return token
627-
}
628-
}
614+
var data map[string]any
615+
if err := json.Unmarshal([]byte(authData), &data); err != nil {
616+
return ""
629617
}
630-
631-
return ""
618+
token, _ := data["access_token"].(string)
619+
return token
632620
}
633621

634622
type userAgentTransport struct {

0 commit comments

Comments
 (0)