jwttoken

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingPrivateKey = errors.New("missing private key while trying to sign the token")

Functions

This section is empty.

Types

type Claims

type Claims interface {
	jwt.Claims
	SetRegisteredClaims(claims jwt.RegisteredClaims)
}

type Token

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

func New

func New() *Token

New creates a new Token that can be signed as a JWT token, pre-filled with default values for "jti," "iat," and "iss". and can be modified using the "WithExpire" method. It also provides a default signing method, RS256, which can be customized with the "WithMethod" method. To include non-default claims, use the "WithClaims" method. You must provide a valid private key using the "WithPrivateKey" method. To complete the token creation, use the "Sign" method.

func (*Token) Sign

func (t *Token) Sign() (*Token, error)

Sign finalizes the configuration of the JWT and signs it with the private key. If no custom claims have been set, it will sign an empty token with only the "jti" claim.

func (*Token) String

func (t *Token) String() string

String returns the string representation of the signed JWT.

func (*Token) WithClaims

func (t *Token) WithClaims(claims Claims) *Token

WithClaims sets the costum claims of the token. It will subscribe any predefined RegisteredClaims.

func (*Token) WithExpire

func (t *Token) WithExpire(exp time.Time) *Token

WithExpire sets the expiration time for the JWT.

func (*Token) WithMethod

func (t *Token) WithMethod(method jwt.SigningMethod) *Token

WithMethod sets the signing method for the JWT. Default is RS256.

func (*Token) WithPrivateKey

func (t *Token) WithPrivateKey(pk *rsa.PrivateKey) *Token

WithPrivateKey sets the private key for signing the JWT.

Jump to

Keyboard shortcuts

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