token

package
v1.340.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: MIT Imports: 13 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

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

	// ErrInvalidAlgorithm for service.
	ErrInvalidAlgorithm = errors.New("token: invalid algorithm")

	// 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 IsEnabled added in v1.324.0

func IsEnabled(cfg *Config) bool

IsEnabled for token.

Types

type Config added in v1.324.0

type Config struct {
	Kind       string `yaml:"kind,omitempty" json:"kind,omitempty" toml:"kind,omitempty"`
	Key        string `yaml:"key,omitempty" json:"key,omitempty" toml:"key,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

IsPaseto for configuration.

func (*Config) IsPaseto added in v1.324.0

func (c *Config) IsPaseto() bool

IsPaseto 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.Algo) *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() (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.Algo) *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, 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