token

package
v1.390.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: MIT Imports: 18 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidMatch for token.
	ErrInvalidMatch = errors.New("token: invalid match")

	// ErrInvalidIssuer for service.
	ErrInvalidIssuer = errors.New("token: invalid issuer")

	// ErrInvalidAudience for service.
	ErrInvalidAudience = errors.New("token: invalid audience")

	// ErrInvalidTime for service.
	ErrInvalidTime = errors.New("token: invalid time")
)

Module for fx.

Functions

func Generate added in v1.389.0

func Generate(name env.Name, gen *rand.Generator) (string, error)

Generate a token. The format is name_rand(64)_crc32(id).

func IsEnabled added in v1.324.0

func IsEnabled(cfg *Config) bool

IsEnabled for token.

func Verify added in v1.389.0

func Verify(name env.Name, token string) error

Verify if the token matches the segments.

Types

type Config added in v1.324.0

type Config struct {
	Kind       string `yaml:"kind,omitempty" json:"kind,omitempty" toml:"kind,omitempty"`
	Secret     string `yaml:"secret,omitempty" json:"secret,omitempty" toml:"secret,omitempty"`
	Subject    string `yaml:"sub,omitempty" json:"sub,omitempty" toml:"sub,omitempty"`
	Audience   string `yaml:"aud,omitempty" json:"aud,omitempty" toml:"aud,omitempty"`
	Issuer     string `yaml:"iss,omitempty" json:"iss,omitempty" toml:"iss,omitempty"`
	Expiration string `yaml:"exp,omitempty" json:"exp,omitempty" toml:"exp,omitempty"`
}

Config for token.

func (*Config) IsJWT added in v1.324.0

func (c *Config) IsJWT() bool

IsJWT for configuration.

func (*Config) IsKey added in v1.325.0

func (c *Config) IsKey() bool

IsKey for configuration.

func (*Config) IsPaseto added in v1.324.0

func (c *Config) IsPaseto() bool

IsPaseto for configuration.

func (*Config) IsToken added in v1.389.0

func (c *Config) IsToken() bool

IsToken for configuration.

type Generator

type Generator interface {
	// Generate a new token or error.
	Generate(ctx context.Context) (context.Context, []byte, error)
}

Generator allows the implementation of different types generators.

type JWT added in v1.324.0

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

JWT token.

func NewJWT added in v1.324.0

func NewJWT(kid KID, ed ed25519.Signer, gen id.Generator) *JWT

NewJWT token.

func (*JWT) Generate added in v1.324.0

func (j *JWT) Generate(sub, aud, iss string, exp time.Duration) (string, error)

Generate JWT token.

func (*JWT) Verify added in v1.324.0

func (j *JWT) Verify(token, aud, iss string) (string, error)

Verify JWT token.

type KID added in v1.324.0

type KID string

KID is a key ID.

func NewKID added in v1.324.0

func NewKID(gen *rand.Generator) (KID, error)

NewKID for JWKSets.

type Paseto added in v1.324.0

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

Paseto token.

func NewPaseto added in v1.324.0

func NewPaseto(ed ed25519.Signer, gen id.Generator) *Paseto

NewPaseto token.

func (*Paseto) Generate added in v1.324.0

func (p *Paseto) Generate(sub, aud, iss string, exp time.Duration) (string, error)

Generate Paseto token.

func (*Paseto) Verify added in v1.324.0

func (p *Paseto) Verify(token, aud, iss string) (string, error)

Verify Paseto token.

type Token added in v1.324.0

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

Token will generate and verify based on what is defined in the config.

func NewToken added in v1.324.0

func NewToken(cfg *Config, name env.Name, jwt *JWT, pas *Paseto) *Token

NewToken based on config.

func (*Token) Generate added in v1.324.0

func (t *Token) Generate(ctx context.Context) (context.Context, []byte, error)

func (*Token) Verify added in v1.324.0

func (t *Token) Verify(ctx context.Context, token []byte) (context.Context, error)

type Verifier

type Verifier interface {
	// Verify a token or error.
	Verify(ctx context.Context, token []byte) (context.Context, error)
}

Verifier allows the implementation of different types of verifiers.

Jump to

Keyboard shortcuts

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