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

authtoken

package
v0.85.3 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const Prefix = "rill"

Prefix is prepended to every auth token.

Variables

View Source
var ErrMalformed = errors.New("malformed auth token")

ErrMalformed is used when attempting to parse an invalid token string.

Functions

This section is empty.

Types

type Token

type Token struct {
	Type   Type
	ID     uuid.UUID
	Secret [24]byte
}

Token is a parsed authentication token with a type, UUID ID, and 24-byte secret. Tokens can be (de)serialized as strings. Example string representation of a user token: rill_usr_2Dws32dc2FxTThgCQjHerGM1rx9pJLCPQh5QbWjUiwpkZNkCCRrlrK.

func FromID added in v0.78.0

func FromID(typ Type, id uuid.UUID) *Token

FromID returns a Token with the given type and id, and a zero secret.

func FromParts added in v0.49.0

func FromParts(typ Type, id uuid.UUID, secret []byte) (*Token, error)

func FromString

func FromString(s string) (*Token, error)

FromString re-creates a token from it's string representation (acquired by calling String()). The things I do for pretty tokens.

func MatchByPrefix added in v0.78.0

func MatchByPrefix(input string, tokens []*Token) []*Token

MatchByPrefix attempts to match a decoded token by its prefix.

func NewRandom

func NewRandom(t Type) *Token

NewRandom generates a securely random token.

func (*Token) Prefix added in v0.78.0

func (t *Token) Prefix() string

Prefix returns a safe, partial display string for the token, e.g., "rill_usr_abcdefghij". This works even if t.Secret is empty (all zeroes), as long as t.ID is set.

func (*Token) SecretHash

func (t *Token) SecretHash() []byte

SecretHash returns a SHA256 hash of the token secret.

func (*Token) String

func (t *Token) String() string

String canonically encodes the token as string.

type Type

type Type string

Type is part of the token prefix in the string representation.

const (
	TypeUser       Type = "usr"
	TypeService    Type = "svc"
	TypeDeployment Type = "dpl"
	TypeMagic      Type = "mgc"
)

func (Type) Validate

func (t Type) Validate() bool

Validate checks that the type is a known enum value.

Jump to

Keyboard shortcuts

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