token

package
v0.0.0-...-daedb85 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 12 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 GenerateECDSASecret

func GenerateECDSASecret() ([]byte, error)

func GenerateJWTSecret

func GenerateJWTSecret() []byte

func IsNoTokenFoundError

func IsNoTokenFoundError(err error) bool

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 WithRelativeDuration

func WithRelativeDuration(dur time.Duration) 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 {
	SigningHash() string
	Hash() string

	PublicKey() []string

	Sign(claims Claims) (string, error)
	Validate(token string) (Token, error)

	KeyFunc(token *jwt.Token) (any, error)

	Method() jwt.SigningMethod

	Details(token string) (*string, []string, time.Duration, error)

	Exists() bool
}

func EmptySecret

func EmptySecret() Secret

func NewECDSAFromData

func NewECDSAFromData(data []byte) (Secret, error)

func NewECDSASecret

func NewECDSASecret(key *ecdsa.PrivateKey, public ...*ecdsa.PublicKey) (Secret, error)

func NewECDSASignSecret

func NewECDSASignSecret(key *ecdsa.PrivateKey) (Secret, error)

func NewECDSAValidateSecret

func NewECDSAValidateSecret(key *ecdsa.PublicKey) (Secret, error)

func NewECDSAValidateSecretSet

func NewECDSAValidateSecretSet(keys ...*ecdsa.PublicKey) ([]Secret, error)

func NewJWTSecret

func NewJWTSecret(data []byte) Secret

func NewJWTSecretWithSize

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

func NewSecret

func NewSecret(data []byte) Secret

func NewSecretSet

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

func NewSecrets

func NewSecrets(secrets ...Secret) Secret

func ValidateOnly

func ValidateOnly(in Secret) Secret

type Secrets

type Secrets []Secret

func (Secrets) Details

func (s Secrets) Details(token string) (*string, []string, time.Duration, error)

func (Secrets) Exists

func (s Secrets) Exists() bool

func (Secrets) Hash

func (s Secrets) Hash() string

func (Secrets) KeyFunc

func (s Secrets) KeyFunc(token *jwt.Token) (any, error)

func (Secrets) Method

func (s Secrets) Method() jwt.SigningMethod

func (Secrets) PublicKey

func (s Secrets) PublicKey() []string

func (Secrets) Sign

func (s Secrets) Sign(claims Claims) (string, error)

func (Secrets) SigningHash

func (s Secrets) SigningHash() string

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 Secret) (Token, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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