Documentation
¶
Index ¶
- Constants
- Variables
- func AccessTokenNotAfter(ctx context.Context) time.Time
- func AuthorizationServerMetadata(baseURL string, dynamicRegistration bool) echo.HandlerFunc
- func Authorize(authService authapp.AuthenticationService, ...) echo.HandlerFunc
- func Callback(authService authapp.AuthenticationService, sessionStore sessions.Store, ...) echo.HandlerFunc
- func GenerateRefreshToken() (string, error)
- func HashToken(token string) string
- func IsNativeRefreshToken(token *OAuthRefreshToken) bool
- func IsProtectedResourceMetadataRequest(method, path string) bool
- func IssuedToConnector(claims *authapp.PericarpClaims) bool
- func MaskCode(code string) string
- func NativeFamilyCap(ctx context.Context, repo RefreshTokenRepository, stored *OAuthRefreshToken) (*time.Time, error)
- func NativeRefreshSuccessorInGrace(ctx context.Context, repo RefreshTokenRepository, spent *OAuthRefreshToken, ...) (successor *OAuthRefreshToken, refresh NativeRefreshToken, ok bool, err error)
- func NativeRefreshSuccessorKey(svc authapp.JWTService) []byte
- func NativeSessionClaims(ctx context.Context, _ *authentities.Agent, _ []*authentities.Account, ...) (map[string]any, error)
- func NativeSessionOf(claims *authapp.PericarpClaims) string
- func NewNativeSessionID() string
- func ProtectedResourceMetadata(baseURL, defaultResource string, knownResources map[string]bool) echo.HandlerFunc
- func ProvideJWTService(cfg config.Config) (authapp.JWTService, error)
- func RegisterClient(clientRepo ClientRepository, enabled bool) echo.HandlerFunc
- func SignedClaimsIgnoringExpiry(svc authapp.JWTService, token string) (*authapp.PericarpClaims, error)
- func Token(jwtService authapp.JWTService, codeRepo AuthCodeRepository, ...) echo.HandlerFunc
- func TokensDieOnRestart(cfg config.Config) bool
- func WithAccessTokenNotAfter(ctx context.Context, t time.Time) context.Context
- func WithNativeSession(ctx context.Context, familyID string) context.Context
- type AuthCodeRepository
- type ClientRepository
- type NativeRefreshToken
- func IssueNativeRefreshToken(ctx context.Context, repo RefreshTokenRepository, ...) (NativeRefreshToken, error)
- func IssueNativeRefreshTokenUntil(ctx context.Context, repo RefreshTokenRepository, ...) (NativeRefreshToken, error)
- func RotateNativeRefreshToken(ctx context.Context, repo RefreshTokenRepository, stored *OAuthRefreshToken, ...) (NativeRefreshToken, error)
- type NativeRefreshTokenPurger
- type OAuthAuthorizationCode
- type OAuthClient
- type OAuthRefreshToken
- type RefreshTokenRepository
Constants ¶
const ( NativeClientID = "weos-native" // NativeRefreshTokenTTL is how long a native refresh token lasts. Each // renewal hands back a new one with the full lifetime, so a person who opens // the app at least once a month stays signed in, and a device left unused // for longer signs in again. It is the store's lifetime for a connector's // refresh token too. NativeRefreshTokenTTL = 30 * 24 * time.Hour )
A native sign-in — password or the trusted issuer's assertion — hands an app in a native shell a one-hour access token and no cookie it can use, so on its own the app is signed out every hour (wm-lnimb). The sign-in therefore hands back a refresh token as well, and the app renews at POST /api/auth/refresh.
The refresh token is kept in the same store as a connector's: hashed, rotated on every use, and revoked with its whole family when a rotated one is presented again. It is told apart by NativeClientID, a client id no registration can have (registration mints a KSUID, which has no hyphen). The token endpoint refuses a native refresh token, and the native route refuses a connector's, so neither path can mint the other's kind of access token.
const ( StatusPending = "pending" StatusIssued = "issued" StatusExchanged = "exchanged" // StatusVoided is a code nobody redeemed and nobody now can: the person it // was minted for had their token access ended (wm-fcpzx). Only // StatusIssued exchanges, so a voided row is refused at the token endpoint // exactly as a spent one is, and it stays distinguishable from a code that // was really used. StatusVoided = "voided" )
Authorization code status constants.
const ( TokenUseClaim = "token_use" TokenUseConnector = "oauth" )
The token endpoint and a native sign-in sign their tokens with the same key, and a valid signature is all ValidateToken checks. So every access token the token endpoint issues carries TokenUseClaim set to TokenUseConnector, and a route that must not answer a third-party connector reads it back with IssuedToConnector (wm-8i8ln). A token without the claim is a native sign-in's token, including every token issued before the claim existed.
const NativeRefreshGraceWindow = 30 * time.Second
NativeRefreshGraceWindow is how long after a native refresh token is spent an exact repeat of it still gets the successor that renewal made (wm-3dgs0). An app whose renewal answer was lost on the network retries with the token it still holds, and two requests that renew at once send it twice. Thirty seconds covers a mobile retry and a race, and is short enough that a copy taken from a device is still caught as reuse: a repeat after the window, or a repeat of a token whose successor was already spent, revokes the family.
const NativeRefreshTokenPurgeHorizon = 7 * 24 * time.Hour
NativeRefreshTokenPurgeHorizon is how long past its expiry a native refresh token row is kept (wm-sa7wv). A spent or revoked row stays until then, so presenting it is still caught as reuse, and ends its family, for the token's whole 30-day life and a week after. Past that the token could only ever be refused, which is what an unknown token gets too, so only the reuse signal is lost. A row lives at most NativeRefreshTokenTTL plus the horizon: 37 days.
const NativeRefreshTokenPurgeInterval = time.Hour
NativeRefreshTokenPurgeInterval is the least time between two purges in one process.
const NativeSessionClaim = "native_session"
NativeSessionClaim is the claim on a native session's access token that names the session's refresh token family (wm-utb5c). A sign-out that presents only the access token ends that family, and no other session of the person. The family id is a row id, not a secret: it renews nothing.
const WellKnownProtectedResourcePrefix = "/.well-known/oauth-protected-resource"
WellKnownProtectedResourcePrefix is the RFC 9728 §3.1 well-known URI prefix; resource paths are appended as a suffix.
Variables ¶
var ErrNativeRefreshCapPassed = errors.New("native refresh token: the cap has already passed")
ErrNativeRefreshCapPassed is what IssueNativeRefreshTokenUntil answers for a cap that is not in the future: the family could never renew. It is also what RotateNativeRefreshToken answers for a family whose cap has passed: the successor would be dead on arrival, so none is written and nothing is spent.
var ErrNotFound = errors.New("oauth: not found")
var SupportedScopes = func() map[string]bool { m := make(map[string]bool, len(SupportedScopesList)) for _, s := range SupportedScopesList { m[s] = true } return m }()
SupportedScopes is a set built from SupportedScopesList for fast lookup.
var SupportedScopesList = []string{
"mcp:read",
"mcp:write",
"mcp:admin",
}
SupportedScopesList is the canonical list of scopes the server issues tokens for. Discovery metadata and the validateScope helper both derive from this single source to prevent drift.
Functions ¶
func AccessTokenNotAfter ¶
AccessTokenNotAfter is the time WithAccessTokenNotAfter put on ctx, or zero when it put none.
func AuthorizationServerMetadata ¶
func AuthorizationServerMetadata(baseURL string, dynamicRegistration bool) echo.HandlerFunc
AuthorizationServerMetadata returns a handler for RFC 8414 metadata. GET /.well-known/oauth-authorization-server
func Authorize ¶
func Authorize( authService authapp.AuthenticationService, sessionManager session.SessionManager, sessionStore sessions.Store, clientRepo ClientRepository, codeRepo AuthCodeRepository, credentialRepo authrepos.CredentialRepository, logger entities.Logger, baseURL string, oauthProviderConfigured bool, allowedEmails []string, ) echo.HandlerFunc
Authorize returns a handler for the OAuth authorization endpoint. GET /oauth/authorize
It validates the MCP client's OAuth parameters and then establishes who the resource owner is, by whichever means this instance has:
- A request that already carries a valid session needs no further authentication. The code is issued against that session's identity and the person goes straight back to the client.
- Otherwise, an instance with an OAuth provider hands off to it, exactly as before, and the callback finishes the job.
- An instance with no provider sends the person to its own sign-in with a way back, rather than to a provider it does not have. Without this such an instance could never complete an authorization at all, however well the person was signed in to it.
What the protocol requires is unchanged on every one of those paths: this decides *who* authenticates the resource owner, not what the client must prove.
func Callback ¶
func Callback( authService authapp.AuthenticationService, sessionStore sessions.Store, codeRepo AuthCodeRepository, accountRepo authrepos.AccountRepository, logger entities.Logger, baseURL string, allowedEmails []string, ) echo.HandlerFunc
Callback returns a handler for the OAuth callback after Google authentication. GET /oauth/callback
This handler completes the Google OAuth exchange, resolves the user identity, updates the pending authorization code with the agent/account IDs, and redirects back to the MCP client's redirect_uri with the authorization code.
When allowedEmails is non-empty, an identity whose email is not in the list is rejected before any account is created, so the server admits only known users.
func GenerateRefreshToken ¶
GenerateRefreshToken creates a random refresh token string.
func IsNativeRefreshToken ¶
func IsNativeRefreshToken(token *OAuthRefreshToken) bool
IsNativeRefreshToken reports whether a stored refresh token was handed back by a native sign-in.
func IsProtectedResourceMetadataRequest ¶
IsProtectedResourceMetadataRequest reports whether the given HTTP method and request path target the protected-resource metadata endpoint, in either the bare or path-suffixed form per RFC 9728 §3.1.
func IssuedToConnector ¶
func IssuedToConnector(claims *authapp.PericarpClaims) bool
IssuedToConnector reports whether claims are those of an access token the token endpoint issued to a connector.
func MaskCode ¶
MaskCode returns a safe-to-log identifier for a sensitive credential (authorization code, refresh token, etc.) — the first 8 hex chars of the SHA-256 hash. Never logs the raw value.
func NativeFamilyCap ¶
func NativeFamilyCap(ctx context.Context, repo RefreshTokenRepository, stored *OAuthRefreshToken) (*time.Time, error)
NativeFamilyCap is the cap of the native refresh token family stored belongs to, or nil when the family has none (wm-5u9q7). A row that carries the cap is answered from the row. A row that carries none is checked against the rest of its family, in one query on the indexed family_id: a renewal served by a binary from before the cap existed copies no cap, so its successor carries none, and without this read every later renewal would lose the cap too. A caller that rotates stored gives the row the cap this answers, so the successor carries it again (see RotateNativeRefreshToken).
func NativeRefreshSuccessorInGrace ¶
func NativeRefreshSuccessorInGrace( ctx context.Context, repo RefreshTokenRepository, spent *OAuthRefreshToken, presentedRaw string, successorKey []byte, now time.Time, window time.Duration, ) (successor *OAuthRefreshToken, refresh NativeRefreshToken, ok bool, err error)
NativeRefreshSuccessorInGrace answers the successor of spent, a native refresh token presented again as presentedRaw, when the repeat is inside the grace window: spent was rotated no more than window before now, and the successor that rotation made is still live — not revoked, spent or expired. A family that was revoked, and a successor that was itself spent, are never answered. ok is false, with no error, whenever the repeat is not inside the window. A window of zero or less, or no successor key, turns the grace window off.
func NativeRefreshSuccessorKey ¶
func NativeRefreshSuccessorKey(svc authapp.JWTService) []byte
NativeRefreshSuccessorKey is the key a native refresh token's successor is derived with, so a repeat inside the grace window can be answered the same successor while the store never keeps a raw refresh token. It is derived from the instance's signing key when svc is the service ProvideJWTService built, so it is the same across a restart and on every process that shares JWT_SIGNING_KEY. Otherwise it is random for this process, and a repeat that reaches another process is reuse, as it was before the grace window existed.
func NativeSessionClaims ¶
func NativeSessionClaims( ctx context.Context, _ *authentities.Agent, _ []*authentities.Account, _ string, ) (map[string]any, error)
NativeSessionClaims is the authentication service's claims enricher: it adds NativeSessionClaim to an access token issued with a ctx from WithNativeSession, and nothing to any other token.
func NativeSessionOf ¶
func NativeSessionOf(claims *authapp.PericarpClaims) string
NativeSessionOf is the refresh token family an access token's claims name, or "" when they name none.
func NewNativeSessionID ¶
func NewNativeSessionID() string
NewNativeSessionID is the id of a new native session: the family id of its refresh tokens, and the id of the first one. It is chosen before the access token is issued, so the token can name it.
func ProtectedResourceMetadata ¶
func ProtectedResourceMetadata(baseURL, defaultResource string, knownResources map[string]bool) echo.HandlerFunc
ProtectedResourceMetadata serves RFC 9728 §3.1 metadata at both the bare well-known path and the path-suffixed form. defaultResource backs the bare path; a non-empty suffix must match an entry in knownResources. Anything else — unknown suffix, foreign path, or bare path with empty defaultResource — returns 404 so the server doesn't advertise metadata for resources it doesn't expose.
func ProvideJWTService ¶
func ProvideJWTService(cfg config.Config) (authapp.JWTService, error)
ProvideJWTService creates the pericarp RSAJWTService that signs and checks the authorization server's access tokens: the bearer tokens MCP connectors present at /api/mcp and /api/agent/*.
JWT_SIGNING_KEY is honored whenever the instance has any sign-in (config.Config.AuthEnabled: an OAuth provider, password sign-in, or a trusted issuer), because every such instance mounts the authorization server and hands out tokens. A PEM-encoded RSA private key keeps those tokens valid across a restart, an idle-stop wake and replicas; empty or "auto" generates an ephemeral key, so every token dies with the process — suitable for development only. A malformed key on such an instance stops boot rather than silently logging every connector out at the next restart.
An instance with no sign-in mounts no authorization server and issues no tokens, so there the key is ignored and an ephemeral one is used: a malformed JWT_SIGNING_KEY left in a development environment does not stop the server starting.
func RegisterClient ¶
func RegisterClient(clientRepo ClientRepository, enabled bool) echo.HandlerFunc
RegisterClient returns a handler for RFC 7591 Dynamic Client Registration. POST /oauth/register
func SignedClaimsIgnoringExpiry ¶
func SignedClaimsIgnoringExpiry(svc authapp.JWTService, token string) (*authapp.PericarpClaims, error)
SignedClaimsIgnoringExpiry reads the claims of an access token this instance signed, whether or not it has expired. Only a native sign-out uses it, to learn which session an app whose token has expired is ending; it must never admit a request. It answers an error for a token whose signature does not verify with the instance's key, and for a service ProvideJWTService did not build.
func Token ¶
func Token( jwtService authapp.JWTService, codeRepo AuthCodeRepository, refreshRepo RefreshTokenRepository, agentRepo authrepos.AgentRepository, accountRepo authrepos.AccountRepository, logger entities.Logger, ) echo.HandlerFunc
Token returns a handler for the OAuth token endpoint. POST /oauth/token
func TokensDieOnRestart ¶
TokensDieOnRestart reports whether the service ProvideJWTService builds for cfg signs with a key made when the process starts, so that no token it issues is valid after a restart, an idle-stop wake or on another replica.
func WithAccessTokenNotAfter ¶
WithAccessTokenNotAfter marks ctx as issuing an access token that must not expire after t: the token service ProvideJWTService builds ends the token at t when t comes before its hour (wm-vdax2). A capped native session passes its cap, so neither a sign-in nor a renewal hands back an access token that outlives the session. A zero t changes nothing.
Types ¶
type AuthCodeRepository ¶
type AuthCodeRepository interface {
Create(ctx context.Context, code *OAuthAuthorizationCode) error
FindByCode(ctx context.Context, code string) (*OAuthAuthorizationCode, error)
MarkExchanged(ctx context.Context, code string) error
UpdateIdentity(ctx context.Context, code, agentID, accountID string) error
// VoidUnredeemedForAgent voids every authorization code bound to the agent
// that nobody has exchanged yet, and answers how many. The door's token
// revocation uses it: a code minted before the revocation exchanges for a
// fresh 30-day refresh token after it, because the token endpoint checks
// the code's status, the membership and the agent, and nothing about a
// revocation (wm-fcpzx). A code still pending is not bound to anybody yet
// — the sign-in that would bind it has to happen first — so there is none
// of the agent's to void.
VoidUnredeemedForAgent(ctx context.Context, agentID string) (int64, error)
}
func NewAuthCodeRepository ¶
func NewAuthCodeRepository(db *gorm.DB) AuthCodeRepository
type ClientRepository ¶
type ClientRepository interface {
Create(ctx context.Context, client *OAuthClient) error
FindByID(ctx context.Context, clientID string) (*OAuthClient, error)
}
func NewClientRepository ¶
func NewClientRepository(db *gorm.DB) ClientRepository
type NativeRefreshToken ¶
NativeRefreshToken is a refresh token handed to a native app: the raw value, which the store never keeps, and when it stops renewing.
func IssueNativeRefreshToken ¶
func IssueNativeRefreshToken( ctx context.Context, repo RefreshTokenRepository, agentID, accountID, sessionID string, ) (NativeRefreshToken, error)
IssueNativeRefreshToken starts the family of native refresh tokens sessionID names (see NewNativeSessionID), for the person in the account. An empty sessionID starts a family with a new id. The family has no cap: every rotation hands back the full lifetime.
func IssueNativeRefreshTokenUntil ¶
func IssueNativeRefreshTokenUntil( ctx context.Context, repo RefreshTokenRepository, agentID, accountID, sessionID string, capAt time.Time, ) (NativeRefreshToken, error)
IssueNativeRefreshTokenUntil is IssueNativeRefreshToken for a sign-in whose session has a fixed end (wm-xbd5h). No token of the family it starts expires after capAt: the first expires at capAt or after the full lifetime, whichever comes first, and every rotation keeps to the same cap (see RotateNativeRefreshToken). A zero capAt caps nothing. A capAt that is not in the future issues nothing and answers ErrNativeRefreshCapPassed.
func RotateNativeRefreshToken ¶
func RotateNativeRefreshToken( ctx context.Context, repo RefreshTokenRepository, stored *OAuthRefreshToken, presentedRaw string, successorKey []byte, ) (NativeRefreshToken, error)
RotateNativeRefreshToken replaces stored, presented as presentedRaw, with a new refresh token in the same family, with the full lifetime, in one transaction. A family with a cap (see IssueNativeRefreshTokenUntil) keeps it: the new token expires at the cap when that comes first, and carries the cap on. The cap is the one stored carries; a caller whose row may have lost it to a pre-cap binary reads it with NativeFamilyCap first and sets it on a copy of stored. With a successor key the new token is derived from the presented one, so a repeat inside the grace window can be answered it again (see NativeRefreshSuccessorInGrace); without one it is random. It answers ErrNotFound when stored was already rotated or revoked, which a concurrent renewal with the same token also gets, and ErrNativeRefreshCapPassed, before it touches the store, when the family's cap is not in the future — a cap can pass between a caller's check and the rotation.
type NativeRefreshTokenPurger ¶
type NativeRefreshTokenPurger struct {
// contains filtered or unexported fields
}
NativeRefreshTokenPurger purges native refresh token rows past the horizon from where native refresh tokens are written — a native sign-in and a renewal — at most once every NativeRefreshTokenPurgeInterval, so the purge needs no timer of its own.
func NewNativeRefreshTokenPurger ¶
func NewNativeRefreshTokenPurger(repo RefreshTokenRepository, now func() time.Time) *NativeRefreshTokenPurger
NewNativeRefreshTokenPurger makes a purger over repo. now is the clock; nil is time.Now.
func (*NativeRefreshTokenPurger) MaybePurge ¶
func (p *NativeRefreshTokenPurger) MaybePurge(ctx context.Context) (ran bool, purged int64, err error)
MaybePurge purges when the interval has passed since this process last purged, and reports whether it ran and how many rows it deleted. A purge that fails still counts as the last one, so a failing store is not asked again on every request.
type OAuthAuthorizationCode ¶
type OAuthAuthorizationCode struct {
Code string `gorm:"primaryKey;type:varchar(255)"`
ClientID string `gorm:"type:varchar(255);not null;index"`
AgentID string `gorm:"type:varchar(255)"` // set after identity resolution
AccountID string `gorm:"type:varchar(255)"`
RedirectURI string `gorm:"type:text;not null"`
CodeChallenge string `gorm:"type:varchar(255);not null"`
CodeChallengeMethod string `gorm:"type:varchar(10);not null;default:'S256'"`
Scope string `gorm:"type:varchar(500)"`
State string `gorm:"type:varchar(255)"` // MCP client's state param
Status string `gorm:"type:varchar(20);not null;default:'pending'"` // pending/issued/exchanged/voided
ExpiresAt time.Time
CreatedAt time.Time
}
OAuthAuthorizationCode stores pending and issued authorization codes.
func (OAuthAuthorizationCode) TableName ¶
func (OAuthAuthorizationCode) TableName() string
type OAuthClient ¶
type OAuthClient struct {
ClientID string `gorm:"primaryKey;type:varchar(255)"`
ClientSecret string `gorm:"type:varchar(255)"` // bcrypt hash; empty for public clients
ClientName string `gorm:"type:varchar(255);not null"`
// JSON arrays. Defaults are populated by the registration handler
// (not via GORM defaults, since SQL string literals can't represent
// JSON arrays without escaping issues across drivers).
RedirectURIs string `gorm:"type:text;not null"`
GrantTypes string `gorm:"type:text;not null"`
ResponseTypes string `gorm:"type:text;not null"`
TokenEndpointAuthMethod string `gorm:"type:varchar(50);not null;default:'none'"`
Scope string `gorm:"type:varchar(500)"`
CreatedAt time.Time
}
OAuthClient stores dynamically registered MCP clients (RFC 7591).
func (OAuthClient) TableName ¶
func (OAuthClient) TableName() string
type OAuthRefreshToken ¶
type OAuthRefreshToken struct {
ID string `gorm:"primaryKey;type:varchar(255)"`
TokenHash string `gorm:"type:varchar(255);not null;uniqueIndex"` // SHA-256 of token
AgentID string `gorm:"type:varchar(255);not null;index"`
AccountID string `gorm:"type:varchar(255)"`
ClientID string `gorm:"type:varchar(255);not null"`
FamilyID string `gorm:"type:varchar(255);not null;index"`
Scope string `gorm:"type:varchar(500)"`
ExpiresAt time.Time
Revoked bool `gorm:"not null;default:false"`
// SuccessorID is the id of the token a rotation replaced this one with, and
// RotatedAt is when. Set only by a rotation, never by another revocation, so
// a native renewal repeated inside the grace window can be answered that
// successor (wm-3dgs0). The successor itself is kept by hash like any token.
SuccessorID string `gorm:"type:varchar(255)"`
RotatedAt *time.Time
// FamilyExpiresAt, when set, is the latest any token of the family may
// expire: a rotation gives the successor the full lifetime or this,
// whichever comes first, and copies it on (wm-xbd5h). A sign-in whose
// session has a fixed end sets it, so renewing cannot outlive the
// session. Nil, as on every row written before it existed, caps nothing.
FamilyExpiresAt *time.Time
CreatedAt time.Time
}
OAuthRefreshToken stores refresh tokens with revocation support. FamilyID groups tokens that descend from the same initial issuance via rotation. When a revoked token is presented (replay/theft signal), the entire family is revoked to invalidate any tokens an attacker may hold.
func (OAuthRefreshToken) TableName ¶
func (OAuthRefreshToken) TableName() string
type RefreshTokenRepository ¶
type RefreshTokenRepository interface {
Create(ctx context.Context, token *OAuthRefreshToken, rawToken string) error
FindByTokenHash(ctx context.Context, tokenHash string) (*OAuthRefreshToken, error)
Revoke(ctx context.Context, id string) error
// RevokeIfActive atomically revokes the token only if it is currently
// not revoked. Returns ErrNotFound if the token is missing or already
// revoked. Used for safe rotation under concurrent refresh requests.
RevokeIfActive(ctx context.Context, id string) error
// RevokeFamily revokes all active tokens in the given family. Used as
// a compromise response when a previously-revoked token is presented
// (signals theft of an earlier rotation). It returns nil only once no
// token of the family is active, a successor a concurrent rotation
// committed meanwhile included.
RevokeFamily(ctx context.Context, familyID string) error
// RevokeForAgent revokes every active token the agent holds for clientID,
// in every account and family. A native app's sign-out uses it to end the
// person's native sessions on every device (wm-lnimb). It returns nil
// only once none is active, as RevokeFamily does.
RevokeForAgent(ctx context.Context, agentID, clientID string) error
// RevokeAllForAgent revokes every active token the agent holds, whatever
// client, family or account it belongs to — a connector's and a native
// session's alike — and answers how many it revoked. The trusted issuer's
// revocation call uses it to end one person's token access after a
// password reset at the door (wm-fcpzx), where no client id can be named:
// the person whose password was reset is exactly the person whose every
// token must stop renewing. It returns nil only once none is active, as
// RevokeFamily does.
RevokeAllForAgent(ctx context.Context, agentID string) (int64, error)
// PurgeExpired deletes the tokens held for clientID that expired before
// before, revoked or not, and answers how many (wm-sa7wv; see
// NativeRefreshTokenPurger).
PurgeExpired(ctx context.Context, clientID string, before time.Time) (int64, error)
// FamilyCap answers the earliest family_expires_at any token of familyID
// carries, revoked or not, or nil when none carries one (wm-5u9q7; see
// NativeFamilyCap).
FamilyCap(ctx context.Context, familyID string) (*time.Time, error)
// CapExpiry gives the token id its family's cap capAt: family_expires_at
// becomes capAt unless the row carries an earlier cap, and an expires_at
// after capAt is moved back to it. A row a binary from before the cap wrote
// is healed with it (see NativeFamilyCap).
CapExpiry(ctx context.Context, id string, capAt time.Time) error
// Rotate atomically revokes the old token (only if active) and creates
// the new token in a single transaction. If the old token is already
// revoked, or has expired by the clock read inside that transaction,
// returns ErrNotFound. If the new token cannot be created, the old token
// is NOT revoked (transaction rollback).
Rotate(
ctx context.Context,
oldID string,
newToken *OAuthRefreshToken,
newRawToken string,
) error
}
func NewRefreshTokenRepository ¶
func NewRefreshTokenRepository(db *gorm.DB) RefreshTokenRepository