feat(16.3-01): tracer — g15_ token scopes through composite backend guard
- Add pact.TokenScope/HasTokenScopes and bouncer.ScopeLimit on Principal - Append backend_api_tokens migration; Allows evaluates scope before superuser - Composite guard routes Bearer g15_… to token lookup; smoke tests cover path Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -7,10 +7,22 @@ import (
|
||||
|
||||
type userKey struct{}
|
||||
|
||||
// ScopeLimit restricts a principal to the permission patterns of its personal
|
||||
// API token. Nil means unrestricted (a JWT session). Only a token guard sets
|
||||
// Scope, already filtered to scopes whose methods include the request method.
|
||||
// Full is true for framework scopes that act as the owner on every allowed
|
||||
// method ("*") or on GET/HEAD ("admin:read"). Otherwise Scopes holds one
|
||||
// pattern slice per method-allowed scope (D-03 literal reading).
|
||||
type ScopeLimit struct {
|
||||
Full bool
|
||||
Scopes [][]string
|
||||
}
|
||||
|
||||
// Principal is the authenticated identity stored on the request context.
|
||||
// PreferredLocale empty means no override. TokensValidAfter zero means no cutoff.
|
||||
// IsSuperuser and PermissionGrants are set only for backend-admin principals.
|
||||
// A grant ending in ".*" matches permission codes by prefix.
|
||||
// Scope is set only for personal API token principals.
|
||||
type Principal struct {
|
||||
ID uint
|
||||
MustChangePassword bool
|
||||
@@ -19,6 +31,7 @@ type Principal struct {
|
||||
Backend bool `json:"-"`
|
||||
IsSuperuser bool `json:"-"`
|
||||
PermissionGrants map[string]bool `json:"-"`
|
||||
Scope *ScopeLimit `json:"-"`
|
||||
}
|
||||
|
||||
// WithUser stores the verified principal on ctx.
|
||||
|
||||
Reference in New Issue
Block a user