jwt

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKeyID

func GenerateKeyID(random []byte) string

func ParseUnverified

func ParseUnverified(tokenString string, claims jwt.Claims) (*jwt.Token, []string, error)

Types

type JWT

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

func New

func New(opts ...Option) (*JWT, error)

New function get secret key and options and return a new JWT instance.

Default expiration function is time.Now().Add(time.Hour).Unix().

func (*JWT) ExpFunc

func (t *JWT) ExpFunc() int64

func (*JWT) Generate

func (t *JWT) Generate(mapClaims map[string]interface{}, expDate int64) (string, error)

Generate function get custom values and add 'exp' as expires at with expDate argument with unix format.

func (*JWT) GivenKey

func (t *JWT) GivenKey() map[string]keyfunc.GivenKey

GivenKey useful for mixing other keys in jwks function.

jwks, err := authProvider.JWTKeyFunc(auth.WithContext(ctx), auth.WithGivenKeys(
	serverJWT.GivenKey(),
))

func (*JWT) Jwks

func (t *JWT) Jwks() models.InfKeyFunc

func (*JWT) Parse

func (t *JWT) Parse(tokenStr string, claims jwt.Claims) (*jwt.Token, error)

Parse is validating and getting claims.

func (*JWT) Renew

func (t *JWT) Renew(tokenStr string, expDate int64) (string, error)

Renew token with not changing claims.

type Option

type Option func(options *option)

func WithECDSAPrivateKey

func WithECDSAPrivateKey(secret *ecdsa.PrivateKey) Option

func WithECDSAPublicKey

func WithECDSAPublicKey(secret *ecdsa.PublicKey) Option

func WithED25519PrivateKey

func WithED25519PrivateKey(secret ed25519.PrivateKey) Option

func WithED25519PublicKey

func WithED25519PublicKey(secret ed25519.PublicKey) Option

func WithExpFunc

func WithExpFunc(fn func() int64) Option

WithExpFunc sets the expiration function for the JWT.

func WithKID

func WithKID(kid string) Option

WithKID sets the key ID for the JWT.

func WithMethod

func WithMethod(method jwt.SigningMethod) Option

WithMethod sets the signing method for the JWT.

func WithRSAPrivateKey

func WithRSAPrivateKey(secret *rsa.PrivateKey) Option

func WithRSAPublicKey

func WithRSAPublicKey(secret *rsa.PublicKey) Option

func WithSecretByte

func WithSecretByte(secret []byte) Option

Jump to

Keyboard shortcuts

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