jwt

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const Audience = "Rumors"

Variables

View Source
var (
	ErrTokenInvalidAudience  = errors.New("token has invalid audience")
	ErrTokenExpired          = errors.New("token is expired")
	ErrTokenUsedBeforeIssued = errors.New("token used before issued")
	ErrTokenNotValidYet      = errors.New("token is not valid yet")
)
View Source
var (
	ErrKeyMustBePEMEncoded = errors.New("invalid key: Key must be a PEM encoded PKCS1 or PKCS8 key")
	ErrNotRSAPrivateKey    = errors.New("key is not a valid RSA private key")
	ErrNotRSAPublicKey     = errors.New("key is not a valid RSA public key")
)
View Source
var (
	ErrNoPrivKeyFile  = errors.New("private key file unreadable")
	ErrInvalidPrivKey = errors.New("RSA private key invalid")
	ErrNoPubKeyFile   = errors.New("public key file unreadable")
	ErrInvalidPubKey  = errors.New("RSA public key invalid")
)
View Source
var (
	ErrInvalidSigningAlgorithm = errors.New("invalid signing algorithm")
	ErrTokenInvalidClaims      = errors.New("token has invalid claims")
)

Functions

func GetKey

func GetKey(key string) ([]byte, error)

func GetRSAPrivateKey

func GetRSAPrivateKey(key string) (*rsa.PrivateKey, error)

func GetRSAPublicKey

func GetRSAPublicKey(key string) (*rsa.PublicKey, error)

func ParseRSAPrivateKeyFromPEM

func ParseRSAPrivateKeyFromPEM(key []byte) (pkey *rsa.PrivateKey, err error)

ParseRSAPrivateKeyFromPEM parses a PEM encoded PKCS1 or PKCS8 private key

func ParseRSAPublicKeyFromPEM

func ParseRSAPublicKeyFromPEM(key []byte) (pkey *rsa.PublicKey, err error)

ParseRSAPublicKeyFromPEM parses a PEM encoded PKCS1 or PKCS8 public key

func RegisteredClaims

func RegisteredClaims(id string, ttl time.Duration) jwt.RegisteredClaims

Types

type Signer

type Signer interface {
	Sign(claims any) (string, error)
}

func NewSigner

func NewSigner(privKey *rsa.PrivateKey) (Signer, error)

type UserClaims

type UserClaims struct {
	jwt.RegisteredClaims
	Username  string                `json:"username,omitempty"`
	Email     string                `json:"email,omitempty"`
	Roles     []models.Role         `json:"roles,omitempty"`
	Providers []models.ProviderData `json:"providers,omitempty"`
	Metadata  any                   `json:"metadata,omitempty"`
}

func Unmarshal

func Unmarshal(claims json.RawMessage) (UserClaims, error)

func (UserClaims) Validate

func (uc UserClaims) Validate() error

type Verifier

type Verifier interface {
	Parse(token string) (*jwt.Token, UserClaims, error)
}

func NewVerifier

func NewVerifier(pubKey *rsa.PublicKey) (Verifier, error)

Jump to

Keyboard shortcuts

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