jwt

package module
v0.0.0-...-8297fe0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: MIT Imports: 11 Imported by: 0

README

JWT - JSON Web Token

Copyright (c) 2022, Geert JM Vanderkelen

Resources

Relevant RFCs:

License

Distributed under the MIT license. See LICENSE.md for more information.

Documentation

Index

Constants

View Source
const (
	JOSETypeJWT = "JWT"
)

Variables

View Source
var (
	ErrVerifyFail = errors.New("token verification failed")
)

Functions

func CheckAlgorithm

func CheckAlgorithm(alg Algorithm) error

func EncodeClaims

func EncodeClaims(claims Claimer) (string, error)

func SliceHasString

func SliceHasString[T ~string](haystack []T, needle T) bool

Types

type Algorithm

type Algorithm string
const (
	AlgNone  Algorithm = "none"
	AlgHS256 Algorithm = "HS256"
	AlgHS384 Algorithm = "HS384"
	AlgHS512 Algorithm = "HS512"
	AlgRS256 Algorithm = "RS256"
)

type Claimer

type Claimer interface {
	Encode() (string, error)
}

type ErrAlgorithmNotSupported

type ErrAlgorithmNotSupported struct {
	Algorithm string
}

func (*ErrAlgorithmNotSupported) Error

func (e *ErrAlgorithmNotSupported) Error() string

type ErrDecoding

type ErrDecoding struct {
	Part string
	Err  error
}

func (*ErrDecoding) Error

func (e *ErrDecoding) Error() string

type ErrEncoding

type ErrEncoding struct {
	Part string
	Err  error
}

func (*ErrEncoding) Error

func (e *ErrEncoding) Error() string

type Factory

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

func NewFactory

func NewFactory(alg Algorithm, jwk *JWK, claimType Claimer) (*Factory, error)

func (*Factory) Decode

func (f *Factory) Decode(token string) (*jsonWebToken, error)

func (*Factory) New

func (f *Factory) New(claims Claimer) (*jsonWebToken, error)

func (*Factory) Verify

func (f *Factory) Verify(token string) (*jsonWebToken, error)

type JOSEHeader

type JOSEHeader struct {
	Algorithm   Algorithm `json:"alg,omitempty"`
	Type        string    `json:"typ,omitempty"`
	ContentType string    `json:"cty,omitempty"`
	KeyID       string    `json:"kid,omitempty"`
}

JOSEHeader defines a JOSE (JSON Object Singing and Encryption) header specified in RFC 7515.

func (JOSEHeader) Encode

func (jh JOSEHeader) Encode() (string, error)

type JWK

type JWK struct {
	KeyType JWKType
	// contains filtered or unexported fields
}

func JWKeyHMAC

func JWKeyHMAC(key string) *JWK

type JWKType

type JWKType string
const (
	JWKOct JWKType = "oct"
)

type RegisteredClaims

type RegisteredClaims struct {
	Issuer    string                   `json:"iss,omitempty"`
	Subject   string                   `json:"sub,omitempty"`
	Audience  StringOrSlice            `json:"aud,omitempty"`
	ExpiresAt *numericdate.NumericDate `json:"exp,omitempty"`
	NotBefore *numericdate.NumericDate `json:"nbf,omitempty"`
	IssuedAt  *numericdate.NumericDate `json:"iat,omitempty"`
	JWTID     string                   `json:"jti,omitempty"`
}

RegisteredClaims defines the registered JWT claims according to RFC7519, section 4.1. It also holds any public claims.

func NewRegisteredClaims

func NewRegisteredClaims() (*RegisteredClaims, error)

func (*RegisteredClaims) Encode

func (clms *RegisteredClaims) Encode() (string, error)

type StringOrSlice

type StringOrSlice []string

func (StringOrSlice) MarshalJSON

func (s StringOrSlice) MarshalJSON() ([]byte, error)

func (*StringOrSlice) UnmarshalJSON

func (s *StringOrSlice) UnmarshalJSON(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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