Documentation
¶
Overview ¶
Package token implements VersionGate's API Token domain concept: issuing, verifying, and revoking Project-scoped bearer credentials (specs/decisions/authentication.md). Like internal/project, this package has no dependency on any specific storage technology.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalid = errors.New("token: invalid or revoked")
ErrInvalid is returned by Verify when raw does not correspond to any active token. It covers both "no such token" and "revoked token" — callers cannot distinguish which, by design: telling them apart would leak whether a given token value ever existed (specs/decisions/authentication.md).
var ErrNotFound = errors.New("token: not found")
ErrNotFound is returned by a Repository when no Token matches a given hash or ID.
Functions ¶
This section is empty.
Types ¶
type ID ¶
type ID string
ID identifies an API Token record. Like project.ID, it is assigned by a Repository at creation time.
type Repository ¶
type Repository interface {
Create(ctx context.Context, projectID project.ID, tokenHash string) (Token, error)
GetByHash(ctx context.Context, tokenHash string) (Token, error)
Revoke(ctx context.Context, id ID) (Token, error)
}
Repository persists and retrieves Tokens. Infrastructure provides the implementation; only a hash is ever passed to or read from it — the raw token value never reaches storage.
type Token ¶
type Token struct {
ID ID
ProjectID project.ID
CreatedAt time.Time
RevokedAt *time.Time // nil means the token is active.
}
Token is metadata about an issued API Token. The raw secret value itself is never part of this type — see Issue's return value for the only place it is ever available.
func Issue ¶
Issue generates a new random token for projectID, persists only its hash via repo, and returns both the Token record and the raw secret value. The raw value is never stored and is only ever available here, at creation — callers must show it to the operator immediately, since it cannot be recovered afterward.
func Revoke ¶
Revoke immediately invalidates the token identified by id. Revoking an already-revoked token is not an error — it is idempotent, and does not change the original revocation time.