auth

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidToken  = errors.New("invalid API token")
	ErrTokenNotFound = errors.New("API token not found")
)

Functions

This section is empty.

Types

type Principal

type Principal struct {
	TokenID string
	Name    string
	Scopes  map[string]struct{}
}

Principal is the authenticated identity stored in a request context.

func (Principal) HasScope

func (p Principal) HasScope(scope string) bool

HasScope reports whether the principal grants the requested scope.

type Store

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

Store persists hashed API tokens in one private JSON file.

func NewStore

func NewStore(path string) (*Store, error)

NewStore loads a token store from path.

func (*Store) Authenticate

func (s *Store) Authenticate(raw string) (Principal, error)

Authenticate validates a raw API token.

func (*Store) Create

func (s *Store) Create(name string, scopes []string, expiresAt *time.Time) (Token, string, error)

Create generates one API token. The raw value is returned only once.

func (*Store) List

func (s *Store) List() []Token

List returns token metadata without secret hashes.

func (*Store) Revoke

func (s *Store) Revoke(id string) error

Revoke prevents all future use of a token.

type Token

type Token struct {
	ID        string     `json:"id"`
	Name      string     `json:"name"`
	Hash      string     `json:"hash,omitempty"`
	Scopes    []string   `json:"scopes"`
	CreatedAt time.Time  `json:"createdAt"`
	ExpiresAt *time.Time `json:"expiresAt,omitempty"`
	RevokedAt *time.Time `json:"revokedAt,omitempty"`
}

Token describes one API token without exposing its secret value.

Jump to

Keyboard shortcuts

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