refreshtoken

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package refreshtoken is the ESP User refresh-token service: it owns the token lifecycle — mint a family on login, rotate-on-use with reuse=theft detection, and revoke — over the espuser-refresh-tokens store. Tokens are signed, self-describing structures (not opaque random strings): each carries user_id|client_id|family_id|counter with an HMAC, so validity is a signature check plus a single family-row counter compare, and nothing per-token is stored. It mirrors the jwt package (a stateful service over a lower layer): this sits over db/refresh_tokens_db, which stays a pure DynamoDB store.

Index

Constants

View Source
const (
	TokenTTL = 365 * 24 * time.Hour // 1 year; sliding window, re-stamped on each rotation

)

Variables

This section is empty.

Functions

func IsReuse

func IsReuse(err error) bool

IsReuse reports whether an error from Rotate is the reuse/theft signal.

Types

type Rotation

type Rotation struct {
	Token  string
	UserID string
	Scope  string
}

Rotation is the result of redeeming a refresh token: the freshly-minted token plus the user/scope carried on the family, from which the caller re-mints the access/id tokens.

type Service

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

Service issues and rotates signed refresh tokens against the refresh-tokens store.

func NewService

func NewService(rmngCtx *rmngctx.RmngContext) *Service

NewService builds a refresh-token service bound to the request context.

func (*Service) MintRefreshtoken

func (s *Service) MintRefreshtoken(userID, clientID, scope string) (token string, err error)

MintRefreshtoken creates a new rotation family for a login: a family row at counter 0 and the first signed token. The family carries user + scope so a later Rotate re-mints the access/id tokens.

func (*Service) RevokeAllForUser

func (s *Service) RevokeAllForUser(userID string) error

RevokeAllForUser ends every session for a user — "sign out everywhere", password reset, or compromise response — by deleting all their family rows in one user-partition query.

func (*Service) RevokeFamily

func (s *Service) RevokeFamily(refreshToken string) error

RevokeFamily terminates the whole family a token belongs to — the /oauth2/revoke endpoint (RFC 7009 §2.1: revoking a token MAY revoke the underlying grant), sign-out, and detected theft all end the login by deleting its family row. An unparseable token is a no-op error.

func (*Service) Rotate

func (s *Service) Rotate(clientID, refreshToken string) (*Rotation, error)

Rotate redeems a refresh token: verify signature, match the family's counter, then advance it atomically and issue the next token. A presented counter below the family's current one is reuse (theft): the family is deleted and an error returned.

Jump to

Keyboard shortcuts

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