token

package
v0.0.0-...-3c4c4c4 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClaimISS               = "iss"
	ClaimISSValue          = "arangodb"
	ClaimEXP               = "exp"
	ClaimIAT               = "iat"
	ClaimPreferredUsername = "preferred_username"
	ClaimRoles             = "roles"
	ClaimServerID          = "server_id"
	ClaimAllowedPaths      = "allowed_paths"
)
View Source
const DefaultTokenSecretSize = 64

Variables

View Source
var NotValidToken = errors.Errorf("Token is not valid")

Functions

func DefaultSigningMethod

func DefaultSigningMethod() jwt.SigningMethod

func IsSignatureInvalidError

func IsSignatureInvalidError(err error) bool

func WithAllowedPaths

func WithAllowedPaths(paths ...string) util.ModR[Claims]

func WithCurrentIAT

func WithCurrentIAT() util.ModR[Claims]

func WithDefaultClaims

func WithDefaultClaims() util.ModR[Claims]

func WithDuration

func WithDuration(dur time.Duration) util.ModR[Claims]

func WithExp

func WithExp(time time.Time) util.ModR[Claims]

func WithIAT

func WithIAT(time time.Time) util.ModR[Claims]

func WithKey

func WithKey(key string, value interface{}) util.ModR[Claims]

func WithRoles

func WithRoles(roles ...string) util.ModR[Claims]

func WithServerID

func WithServerID(id string) util.ModR[Claims]

func WithUsername

func WithUsername(username string) util.ModR[Claims]

Types

type Claims

type Claims jwt.MapClaims

func NewClaims

func NewClaims() Claims

func Parse

func Parse(token string, secret []byte) (Claims, error)

func ParseWithAny

func ParseWithAny(token string, secrets ...[]byte) (Claims, error)

func (Claims) Sign

func (t Claims) Sign(secret Secret) (string, error)

func (Claims) With

func (t Claims) With(mods ...util.ModR[Claims]) Claims

type Secret

type Secret interface {
	Hash() string

	Sign(method jwt.SigningMethod, claims Claims) (string, error)
	Validate(token string) (Token, error)

	Exists() bool
}

func EmptySecret

func EmptySecret() Secret

func NewSecret

func NewSecret(data []byte) Secret

func NewSecretSet

func NewSecretSet(main Secret, secondary ...Secret) Secret

func NewSecretWithSize

func NewSecretWithSize(data []byte, size int) Secret

func NewSecrets

func NewSecrets(secrets ...Secret) Secret

type Secrets

type Secrets []Secret

func (Secrets) Exists

func (s Secrets) Exists() bool

func (Secrets) Hash

func (s Secrets) Hash() string

func (Secrets) Sign

func (s Secrets) Sign(method jwt.SigningMethod, claims Claims) (string, error)

func (Secrets) Validate

func (s Secrets) Validate(token string) (Token, error)

type Token

type Token interface {
	Claims() Claims
}

func Validate

func Validate(t string, secret []byte) (Token, error)

Jump to

Keyboard shortcuts

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