dcr

package
v0.25.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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.

View Source
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://…).

Variables

View Source
var DefaultRedirectSchemes = []string{schemeHTTPS, SchemeLoopback}

DefaultRedirectSchemes applies when a host configures none.

View Source
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

func FilterGrantTypes(grants []string) []string

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

func FilterRedirectURIs(uris, schemes []string) []string

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.

func (*ConsentStore) Revoke added in v0.23.0

func (s *ConsentStore) Revoke(ctx context.Context, subject, clientID, redirectURI string) error

Revoke removes subject's consent for clientID at redirectURI.

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore(cm cache.CacheManager, host string, ttl time.Duration, maxClients int32) *Store

func (*Store) Delete added in v0.23.0

func (s *Store) Delete(ctx context.Context, clientID string) error

Delete removes a client record. Used when a stored client no longer has any redirect the current policy admits, so it cannot come back if the policy is relaxed again.

func (*Store) Get

func (s *Store) Get(ctx context.Context, clientID string) (Client, bool, error)

func (*Store) Register

func (s *Store) Register(ctx context.Context, c Client) (Client, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL