token

package
v1.458.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: MIT Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// EmptyKID is the kid used when no kid is provided.
	EmptyKID = KID("")
)

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 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"`
	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"`
	KeyID      string `yaml:"kid,omitempty" json:"kid,omitempty" toml:"kid,omitempty"`
}

Config for token.

func (*Config) IsJWT added in v1.324.0

func (c *Config) IsJWT() bool

IsJWT for configuration.

func (*Config) IsOpaque added in v1.452.0

func (c *Config) IsOpaque() bool

IsOpaque 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, signer *ed25519.Signer, generator 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(cfg *Config) KID

NewKID for JWKSets.

type Opaque added in v1.451.0

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

Opaque represents an opaque token.

func NewOpaque added in v1.451.0

func NewOpaque(name env.Name, generator *rand.Generator) *Opaque

NewOpaque creates a new opaque token.

func (*Opaque) Generate added in v1.451.0

func (o *Opaque) Generate() string

Generate generates a new opaque token.

func (*Opaque) Verify added in v1.451.0

func (o *Opaque) Verify(token string) error

Verify verifies an opaque token.

type Params added in v1.451.0

type Params struct {
	fx.In

	Config *Config
	JWT    *JWT
	Paseto *Paseto
	Opaque *Opaque
	Name   env.Name
}

Params for token.

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(signer *ed25519.Signer, generator 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(params Params) *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