fix: Update ScopesSupported to match RFC 9728 Section 2

This commit is contained in:
Alex Leach 2025-10-12 21:26:05 +01:00
parent 56d969b785
commit 8ca4bb4787
No known key found for this signature in database
GPG key ID: 46E1D1A0150DEEA3
5 changed files with 17 additions and 66 deletions

View file

@ -53,9 +53,8 @@ protected_resource_metadata:
resource_identifier: http://localhost:8080/sse
audience: 2xGW_poFYoObUE_vUQxvGdPSUPwa
scopes_supported:
- initialize: "mcp_init"
- tools/call:
- echo_tool: "mcp_echo_tool"
- "read:tools"
- "read:resources"
authorization_servers:
- https://api.asgardeo.io/t/openmcpauthdemo/oauth2/token
jwks_uri: https://api.asgardeo.io/t/openmcpauthdemo/oauth2/jwks

View file

@ -100,10 +100,17 @@ func (p *defaultProvider) ProtectedResourceMetadataHandler() http.HandlerFunc {
w.Header().Set("Content-Type", "application/json")
meta := map[string]interface{}{
"audience": p.cfg.ProtectedResourceMetadata.Audience,
"scopes_supported": p.cfg.ProtectedResourceMetadata.ScopesSupported,
"authorization_servers": p.cfg.ProtectedResourceMetadata.AuthorizationServers,
}
if len(p.cfg.ProtectedResourceMetadata.ScopesSupported) > 0 {
meta["scopes_supported"] = p.cfg.ProtectedResourceMetadata.ScopesSupported
}
if p.cfg.ProtectedResourceMetadata.ResourceIdentifier != "" {
meta["resource"] = p.cfg.ProtectedResourceMetadata.ResourceIdentifier
}
if p.cfg.ProtectedResourceMetadata.JwksURI != "" {
meta["jwks_uri"] = p.cfg.ProtectedResourceMetadata.JwksURI
}

View file

@ -7,7 +7,6 @@ import (
"github.com/golang-jwt/jwt/v4"
"github.com/wso2/open-mcp-auth-proxy/internal/config"
"github.com/wso2/open-mcp-auth-proxy/internal/util"
)
type ScopeValidator struct{}
@ -18,11 +17,7 @@ func (d *ScopeValidator) ValidateAccess(
claims *jwt.MapClaims,
config *config.Config,
) AccessControlResult {
env, err := util.ParseRPCRequest(r)
if err != nil {
return AccessControlResult{DecisionDeny, "bad JSON-RPC request"}
}
requiredScopes := util.GetRequiredScopes(config, env)
requiredScopes := config.ProtectedResourceMetadata.ScopesSupported
if len(requiredScopes) == 0 {
return AccessControlResult{DecisionAllow, ""}

View file

@ -70,12 +70,12 @@ type ResponseConfig struct {
}
type ProtectedResourceMetadata struct {
ResourceIdentifier string `yaml:"resource_identifier"`
Audience string `yaml:"audience"`
ScopesSupported []map[string]interface{} `yaml:"scopes_supported"`
AuthorizationServers []string `yaml:"authorization_servers"`
JwksURI string `yaml:"jwks_uri,omitempty"`
BearerMethodsSupported []string `yaml:"bearer_methods_supported,omitempty"`
ResourceIdentifier string `yaml:"resource_identifier"`
Audience string `yaml:"audience"`
ScopesSupported []string `yaml:"scopes_supported"`
AuthorizationServers []string `yaml:"authorization_servers"`
JwksURI string `yaml:"jwks_uri,omitempty"`
BearerMethodsSupported []string `yaml:"bearer_methods_supported,omitempty"`
}
type PathConfig struct {

View file

@ -10,7 +10,6 @@ import (
"strings"
"github.com/golang-jwt/jwt/v4"
"github.com/wso2/open-mcp-auth-proxy/internal/config"
logger "github.com/wso2/open-mcp-auth-proxy/internal/logging"
)
@ -160,55 +159,6 @@ func ParseJWT(tokenStr string) (jwt.MapClaims, error) {
return claims, nil
}
// Process the required scopes
func GetRequiredScopes(cfg *config.Config, requestBody *RPCEnvelope) []string {
var scopeObj interface{}
found := false
for _, m := range cfg.ProtectedResourceMetadata.ScopesSupported {
if val, ok := m[requestBody.Method]; ok {
scopeObj = val
found = true
break
}
}
if !found {
return nil
}
switch v := scopeObj.(type) {
case string:
return []string{v}
case []any:
if requestBody.Params != nil {
if paramsMap, ok := requestBody.Params.(map[string]any); ok {
name, ok := paramsMap["name"].(string)
if ok {
for _, item := range v {
if scopeMap, ok := item.(map[interface{}]interface{}); ok {
if scopeVal, exists := scopeMap[name]; exists {
if scopeStr, ok := scopeVal.(string); ok {
return []string{scopeStr}
}
if scopeArr, ok := scopeVal.([]any); ok {
var scopes []string
for _, s := range scopeArr {
if str, ok := s.(string); ok {
scopes = append(scopes, str)
}
}
return scopes
}
}
}
}
}
}
}
}
return nil
}
// Extracts the Bearer token from the Authorization header
func ExtractAccessToken(authHeader string) (string, error) {