feat(32.2-01): admin consent endpoint for administrator-only MCP grants
- pact: MCPAdminConsent provider interface, MCPAdminConsentRequest,
MCPAdminConsentDecision, ErrMCPConsentNotFound, ErrMCPConsentNoScopes
- cabana: GET/POST {api}/mcp/consent/{request}, interactive-only, scope
policy of personal tokens (requested, catalog, owned; * collapses)
- cabana: TokenScopeNames and TokenScopeLabels export the token-scope catalog
- swag views and annotations; admin.json and schema.d.ts regenerated so the
contract and conformance inventories stay green
- phrasebook keys mcp_connect.request_not_found and no_grantable_scopes
This commit is contained in:
63
modules/cabana/token_scopes_export.go
Normal file
63
modules/cabana/token_scopes_export.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package cabana
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/backpack"
|
||||
"git.golem15.com/golem15/summercms/modules/phrasebook"
|
||||
)
|
||||
|
||||
// TokenScopeNames answers the names of the personal API token scope catalog
|
||||
// in catalog order: *, admin:read, then every plugin's TokenScopes in
|
||||
// activation order. It compiles the catalog from the activated plugins
|
||||
// (party.Activated), so it works at plugin Boot, before cabana.Activate. A
|
||||
// plugin that advertises the same scopes elsewhere (an OAuth server whose
|
||||
// grants act as administrators, for example) reads them here. The error is
|
||||
// the catalog's compile error (an invalid or duplicate plugin scope).
|
||||
func TokenScopeNames(app *backpack.App) ([]string, error) {
|
||||
reg, err := tokenCatalogForApp(app)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if reg == nil || reg.tokenScopes == nil {
|
||||
return []string{}, nil
|
||||
}
|
||||
out := make([]string, 0, len(reg.tokenScopes.ordered))
|
||||
for _, scope := range reg.tokenScopes.ordered {
|
||||
out = append(out, scope.Name)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// TokenScopeLabels answers the translated label of each name, in input
|
||||
// order: the label the token screens show for a catalog scope, and the name
|
||||
// itself for a name the catalog does not know (or when the catalog fails to
|
||||
// compile). The locale is the one ctx carries.
|
||||
func TokenScopeLabels(ctx context.Context, app *backpack.App, names []string) []string {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
var tr *phrasebook.Translator
|
||||
if app != nil {
|
||||
tr, _ = app.Lookup[*phrasebook.Translator]()
|
||||
}
|
||||
reg, err := tokenCatalogForApp(app)
|
||||
out := make([]string, 0, len(names))
|
||||
for _, name := range names {
|
||||
label := name
|
||||
if err == nil && reg != nil && reg.tokenScopes != nil {
|
||||
if scope, ok := reg.tokenScopes.byName[name]; ok {
|
||||
label = scope.Label
|
||||
if strings.Contains(label, "::") {
|
||||
label = resolveScopePhrase(ctx, tr, label, label)
|
||||
}
|
||||
if strings.TrimSpace(label) == "" {
|
||||
label = name
|
||||
}
|
||||
}
|
||||
}
|
||||
out = append(out, label)
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user