Documentation ¶
Overview ¶
Package jwt provides structures and functions to build/parse JWT, read/parse public and private keys.
Index ¶
- Variables
- func GetSigningMethod(alg string) (jwt.SigningMethod, error)
- func NewBuilder(params Params) (*builder, error)
- func NewParser(params Params) (*parser, error)
- func ParsePrivateKey(data []byte, alg string) (any, error)
- func ParsePublicKey(data []byte, alg string) (any, error)
- func ReadPrivateKey(path string, alg string) (any, error)
- func ReadPublicKey(path string, alg string) (any, error)
- type Builder
- type Claims
- type Params
- type Parser
Constants ¶
This section is empty.
Variables ¶
var ( ErrAlgInvalid = errors.New("algorithm is invalid") ErrAlgNone = errors.New("algorithm is none") )
var ErrClaimsInvalid = errors.New("claims is invalid")
Functions ¶
func GetSigningMethod ¶
GetSigningMethod gets jwt.SigningMethod by alg. It returns jwt.SigningMethod or nil if alg is invalid or "none".
func NewBuilder ¶
NewBuilder gets signing method by params and creates new builder. It returns pointer to a builder instance or nil if params.Algorithm is incorrect.
func NewParser ¶
NewParser gets signing method by params and creates new parser. It returns pointer to a parser instance or nil if params.Algorithm is incorrect.
func ParsePrivateKey ¶
ParsePrivateKey creates keyParser and parses private key. It returns private key or nil if parsing failed.
func ParsePublicKey ¶
ParsePublicKey creates keyParser and parses public key. It returns public key or nil if parsing failed.
func ReadPrivateKey ¶
ReadPrivateKey reads private key and parses it. It returns private key or nil if reading/parsing failed.
Types ¶
type Builder ¶
type Builder interface { // Build creates new Claims, JWT string and signing it. // It returns JWT string or empty string if signing failed. Build(subject string, age time.Duration, fingerprint string, roles []string) (string, error) }
Builder is interface implemented by types that can build JWT.
type Claims ¶
type Claims struct { Fingerprint string `json:"fingerprint"` Roles []string `json:"roles"` jwt.RegisteredClaims }
Claims represents custom claims. The jwt.RegisteredClaims embedded in it.