Documentation
¶
Index ¶
- Constants
- Variables
- func FilterGrantTypes(grants []string) []string
- func FilterRedirectURIs(uris, schemes []string) []string
- type Client
- type ConsentStore
- func (s *ConsentStore) Covers(ctx context.Context, subject, clientID, redirectURI string, scopes []string) (bool, error)
- func (s *ConsentStore) Grant(ctx context.Context, subject, clientID, redirectURI string, scopes []string) error
- func (s *ConsentStore) HasClient(ctx context.Context, subject, clientID string, redirects []string) (bool, error)
- func (s *ConsentStore) Revoke(ctx context.Context, subject, clientID, redirectURI string) error
- type Store
Constants ¶
const ( MaxConsentClients = 64 MaxConsentRedirects = 4 MaxConsentScopes = 32 MaxConsentScopeLen = 128 )
Bounds on one subject's consent record (spec 2026-10-08 §6). Without them an authenticated user could grow a single cache value without limit.
const ( SchemeLoopback = "http-loopback" // http, loopback host only (RFC 8252 §7.3) SchemePrivateUse = "private-use" // any dotted non-http(s) scheme (RFC 8252 §7.1) )
Named allowedRedirectSchemes policies. Every other entry is a literal URI scheme ("cursor" permits cursor://…).
const ClientIDPrefix = "dcr_"
ClientIDPrefix starts every dynamically registered client id. It is reserved: no user identity may carry it, which keeps DCR client ids disjoint from user subjects by construction. See kdex-tech/host-manager#243.
Variables ¶
var DefaultRedirectSchemes = []string{schemeHTTPS, SchemeLoopback}
DefaultRedirectSchemes applies when a host configures none.
var SupportedGrantTypes = []string{"authorization_code", "refresh_token"}
SupportedGrantTypes is the complete set a DYNAMICALLY REGISTERED client may hold. It is deliberately narrower than the authorization server's own grant_types_supported: those are available to statically configured clients, which an operator authored and can be held accountable for, whereas a DCR client is anonymous, credential-less and freely re-mintable.
Keep this a redirect-based pair. Adding a grant that authenticates without a redirect (password, client_credentials) hands an unauthenticated caller a working credential-testing client. See GHSA-hm9g-w2cw-j7gg.
Functions ¶
func FilterGrantTypes ¶ added in v0.22.1
FilterGrantTypes applies the DCR grant policy to a client's grants. With none given it returns SupportedGrantTypes (the registration default); otherwise it keeps only the supported ones, preserving order and dropping duplicates. An empty result means nothing given was supported, which every caller must treat as a refusal: an empty grant list reads as "every grant" at the token endpoint.
It runs both when a client registers and when a stored client is read back, so a record persisted before registration filtered grants (pre-v0.5.1) is held to the same policy.
func FilterRedirectURIs ¶ added in v0.23.0
FilterRedirectURIs keeps the redirect URIs the policy admits, in order and without duplicates. It runs at registration AND whenever a stored client is read back, so tightening allowedRedirectSchemes takes effect on clients already registered. An empty result means no usable redirect: the caller refuses (registration) or treats the client as gone (read-back).
Types ¶
type Client ¶
type Client struct {
ClientID string `json:"client_id"`
RedirectURIs []string `json:"redirect_uris"`
GrantTypes []string `json:"grant_types,omitempty"`
ResponseTypes []string `json:"response_types,omitempty"`
Scope string `json:"scope,omitempty"`
ClientName string `json:"client_name,omitempty"`
TokenEndpointAuthMethod string `json:"token_endpoint_auth_method"`
CreatedAt int64 `json:"created_at"`
}
Client is a dynamically-registered (RFC 7591) OAuth client record.
type ConsentStore ¶ added in v0.23.0
type ConsentStore struct {
// contains filtered or unexported fields
}
ConsentStore remembers which dynamically registered clients a user allowed, at which redirect, for which scopes. Uncycled (it must survive a reconcile, like the client store, #122), with the client TTL, sliding with use.
Concurrent updates to one subject's record are last-writer-wins. A lost Grant only means the user is asked again, so no locking. A Revoke is eventually consistent within one cache round trip (cache.Cache has no compare-and-set); touch re-loads before saving so it never resurrects it.
func NewConsentStore ¶ added in v0.23.0
func NewConsentStore(cm cache.CacheManager, ttl time.Duration, maxItems int) *ConsentStore
NewConsentStore builds the store. maxItems bounds the in-memory backend (one item per subject); valkey ignores it. In-memory mode is for dev only.
func NewConsentStoreFromCache ¶ added in v0.23.0
func NewConsentStoreFromCache(c cache.Cache, ttl time.Duration) *ConsentStore
NewConsentStoreFromCache builds a ConsentStore over an existing cache.
func (*ConsentStore) Covers ¶ added in v0.23.0
func (s *ConsentStore) Covers(ctx context.Context, subject, clientID, redirectURI string, scopes []string) (bool, error)
Covers reports whether subject allowed clientID at redirectURI for every scope in scopes (an empty scopes is covered by any grant for the redirect). A stale grant (untouched for a day) is touched, so consent lives as long as the client is in use.
func (*ConsentStore) Grant ¶ added in v0.23.0
func (s *ConsentStore) Grant(ctx context.Context, subject, clientID, redirectURI string, scopes []string) error
Grant records that subject allowed clientID at redirectURI for scopes, adding to what was allowed before, within the record's bounds.
func (*ConsentStore) HasClient ¶ added in v0.23.0
func (s *ConsentStore) HasClient(ctx context.Context, subject, clientID string, redirects []string) (bool, error)
HasClient reports whether subject holds consent for clientID at any of redirects -- the client's redirects as the current policy allows them, so consent given at one the policy has since dropped no longer counts. The refresh grant uses it: a session cannot outlive its consent.