feat(32.2-01): administrator-only MCP grants and a configurable consent handoff
- pact: MCPGrant.Subject with MCPGrantSubjectBackend, MCPSubject.ScopeLimited - pier: a backend-subject grant resolves straight to a scope-limited backend subject bound to oauth:backend:<client>:<admin>, no link lookup, no ceiling - pier: the backend guard scope-limits ScopeLimited subjects like g15_ tokens - wristband: Options.ConsentPath and Options.DefaultScopes; defaults unchanged - smoke tests TestBackendSubjectSmoke (Postgres) and TestConsentPathSmoke
This commit is contained in:
@@ -40,7 +40,8 @@ func (s *Server) allowedAuthorizeScopes() map[string]bool {
|
||||
// middleware). It validates the client and exact redirect before any
|
||||
// redirect response, enforces S256 PKCE syntax, the client's scope ceiling,
|
||||
// and the RFC 8707 resource check, then persists an opaque pending request
|
||||
// and redirects to the app's /connect handoff.
|
||||
// and redirects to the app's consent handoff (Options.ConsentPath on
|
||||
// Issuer, /connect by default).
|
||||
//
|
||||
// On an OIDC server it dispatches to the OIDC flavour before any MCP code
|
||||
// runs: GET starts an authorization request, POST is the consent decision.
|
||||
@@ -106,7 +107,8 @@ func (s *Server) Authorize(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
scopes, scopeErr := parseAuthorizeScopes(q.Get("scope"), s.allowedAuthorizeScopes())
|
||||
allowed := s.allowedAuthorizeScopes()
|
||||
scopes, scopeErr := parseAuthorizeScopes(q.Get("scope"), allowed, s.defaultAuthorizeScopes(allowed))
|
||||
if scopeErr != "" {
|
||||
s.authorizeErrorRedirect(w, redirectURI, "invalid_scope", scopeErr, state)
|
||||
return
|
||||
@@ -184,7 +186,7 @@ func (s *Server) Authorize(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
spa := s.opts.Issuer + "/connect?request=" + rfc3986Escape(requestID)
|
||||
spa := s.opts.Issuer + s.consentPath() + "?request=" + rfc3986Escape(requestID)
|
||||
// Laravel appends ", private" to every explicit Cache-Control this
|
||||
// endpoint sets (session-cookie default merge); recorded PHP traffic is
|
||||
// "no-store, private", never a bare "no-store" (D-04, live-recorded byte
|
||||
@@ -193,6 +195,33 @@ func (s *Server) Authorize(w http.ResponseWriter, r *http.Request) {
|
||||
writeRedirectHTML(w, http.StatusFound, spa)
|
||||
}
|
||||
|
||||
// consentPath is the path the authorize handoff appends to Issuer:
|
||||
// Options.ConsentPath, or the PHP "/connect" while it is empty.
|
||||
func (s *Server) consentPath() string {
|
||||
if s.opts.ConsentPath != "" {
|
||||
return s.opts.ConsentPath
|
||||
}
|
||||
return "/connect"
|
||||
}
|
||||
|
||||
// defaultAuthorizeScopes is the fallback of an authorize request that names
|
||||
// no data scope: Options.DefaultScopes filtered to allowed, in their given
|
||||
// order without repeats, or the PHP ["read"] when nothing remains.
|
||||
func (s *Server) defaultAuthorizeScopes(allowed map[string]bool) []string {
|
||||
out := make([]string, 0, len(s.opts.DefaultScopes))
|
||||
for _, sc := range s.opts.DefaultScopes {
|
||||
sc = strings.TrimSpace(sc)
|
||||
if sc == "" || !allowed[sc] || mcpIgnoredIdentityScopes[sc] || stringSliceContains(out, sc) {
|
||||
continue
|
||||
}
|
||||
out = append(out, sc)
|
||||
}
|
||||
if len(out) == 0 {
|
||||
return []string{"read"}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// writeAuthorizeLocalError writes the PHP localError() response: a bare
|
||||
// text/plain 400 with no Location and no house envelope
|
||||
// (T-08-OPEN-REDIRECT).
|
||||
@@ -236,9 +265,11 @@ var mcpIgnoredIdentityScopes = map[string]bool{
|
||||
// issues no ID tokens and never grants identity scopes (phase 19.4 D-07,
|
||||
// narrowed from refusal to dropping), so the drop happens even when a host
|
||||
// lists one of them in Options.ScopesSupported. An absent, empty or
|
||||
// identity-only scope value falls back to ["read"]; any other token outside
|
||||
// allowed, the server's set (allowedAuthorizeScopes), is refused.
|
||||
func parseAuthorizeScopes(raw string, allowed map[string]bool) ([]string, string) {
|
||||
// identity-only scope value falls back to fallback (the PHP ["read"] unless
|
||||
// Options.DefaultScopes says otherwise, see defaultAuthorizeScopes); any
|
||||
// other token outside allowed, the server's set (allowedAuthorizeScopes),
|
||||
// is refused.
|
||||
func parseAuthorizeScopes(raw string, allowed map[string]bool, fallback []string) ([]string, string) {
|
||||
parts := strings.Fields(strings.TrimSpace(raw))
|
||||
kept := make([]string, 0, len(parts))
|
||||
for _, p := range parts {
|
||||
@@ -247,7 +278,7 @@ func parseAuthorizeScopes(raw string, allowed map[string]bool) ([]string, string
|
||||
}
|
||||
}
|
||||
if len(kept) == 0 {
|
||||
return []string{"read"}, ""
|
||||
return append([]string(nil), fallback...), ""
|
||||
}
|
||||
for _, p := range kept {
|
||||
if !allowed[p] {
|
||||
|
||||
Reference in New Issue
Block a user