Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrMissingPrivateKey = errors.New("missing private key while trying to sign the token")
Functions ¶
This section is empty.
Types ¶
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 ¶
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) WithClaims ¶
WithClaims sets the costum claims of the token. It will subscribe any predefined RegisteredClaims.
func (*Token) WithExpire ¶
WithExpire sets the expiration time for the JWT.
func (*Token) WithMethod ¶
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.