Help us shape the future of Go! Take the 2026 Go Developer Survey

token

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 7 Imported by: 0

README

Session token primitives

NewAccess(key, issuer, audience) creates an immutable HS256 signer/verifier for UUID account and session IDs. The key must contain 32 random bytes. Issue embeds the IDs and expiry; Parse validates algorithm, issuer, audience, timestamps, UUIDs and token type. Errors are package-level sentinels, independent of HTTP.

JWT verification does not establish current authorization or session activity. The application must check revocation and account state. Keep signing keys private; this implementation uses one key and has no overlapping-key rotation mechanism.

NewOpaque() returns a random 256-bit credential and its SHA-256 digest. HashOpaque(raw) accepts only its canonical base64url encoding. Store only the digest; raw credentials must not appear in logs or URLs. Storage, rotation, replay detection, expiry and revocation belong to the application.

Documentation

Overview

Package token issues and validates UUID-based session access tokens using golang-jwt. Refresh credentials are opaque and are not JWTs.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalid = errors.New("token: invalid credential")
	ErrConfig  = errors.New("token: invalid access token configuration")
)

Functions

func HashOpaque

func HashOpaque(raw string) ([]byte, error)

func NewOpaque

func NewOpaque() (string, []byte, error)

NewOpaque returns a random 256-bit credential and its SHA-256 digest. Persist only the digest; the raw credential must not appear in logs or URLs.

Types

type Access

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

func NewAccess

func NewAccess(key []byte, issuer, audience string) (*Access, error)

func (*Access) Issue

func (a *Access) Issue(principal Principal, expires time.Time) (string, error)

func (*Access) Parse

func (a *Access) Parse(raw string) (Principal, error)

type Principal

type Principal struct{ UserID, SessionID uuid.UUID }

Principal identifies a UUID-based account and login session. Authorization and revocation remain the caller's responsibility.

Jump to

Keyboard shortcuts

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