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

auth

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Overview

Package auth defines instance-wide permissions and opaque bearer credentials.

Index

Constants

View Source
const (
	Ingest    = "ingest"
	Inspect   = "inspect"
	Endpoints = "endpoints"
	Replay    = "replay"
	Metrics   = "metrics"
)

Variables

View Source
var ErrUnauthorized = errors.New("unauthorized")

Functions

func Generate

func Generate() (string, error)

Generate returns a 256-bit random credential. Only its hash belongs in storage.

func Hash

func Hash(token string) ([]byte, error)

func ValidPermissions

func ValidPermissions(permissions []string) bool

func WithPrincipal

func WithPrincipal(ctx context.Context, principal Principal) context.Context

Types

type Authenticator

type Authenticator interface {
	Authenticate(context.Context, []byte, time.Time) (Principal, error)
}

type Principal

type Principal struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Kind        string   `json:"kind"`
	Permissions []string `json:"permissions"`
}

func FromContext

func FromContext(ctx context.Context) Principal

func (Principal) Allows

func (p Principal) Allows(permission string) bool

Jump to

Keyboard shortcuts

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