token

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package token implements the Internal Token Service.

Responsibilities:

  • CRUD for RouterTokens
  • Validation of incoming bearer tokens against stored hashes
  • Enforcement of TokenRules

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateOptions

type CreateOptions struct {
	Name  string
	Rules models.TokenRules
}

CreateOptions holds the parameters for issuing a new token.

type Service

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

Service manages router-tokens.

func New

func New(database *db.DB) *Service

New constructs a new token Service.

func (*Service) Create

func (s *Service) Create(opts CreateOptions) (*models.RouterToken, error)

Create mints a new RouterToken and persists it. The raw (unhashed) token value is returned exactly once — it is not stored.

func (*Service) Delete

func (s *Service) Delete(id string) error

Delete removes a RouterToken and its index entry by ID.

func (*Service) Get

func (s *Service) Get(id string) (*models.RouterToken, error)

Get returns a RouterToken by ID.

func (*Service) List

func (s *Service) List() ([]*models.RouterToken, error)

List returns all RouterTokens.

func (*Service) Regenerate

func (s *Service) Regenerate(id string) (*models.RouterToken, error)

Regenerate replaces the secret of an existing token with a new one. The token keeps its ID, Name and Rules; the old secret is invalidated.

func (*Service) UpdateRules

func (s *Service) UpdateRules(id string, rules models.TokenRules) error

UpdateRules replaces the TokenRules for an existing token.

func (*Service) Validate

func (s *Service) Validate(raw string) (*models.RouterToken, error)

Validate looks up the RouterToken matching the provided raw bearer value. Returns ErrUnauthorized if the token is not found.

Jump to

Keyboard shortcuts

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