github.com/golang-jwt/jwt/v5
import "github.com/golang-jwt/jwt/v5"
Package jwt is a Go implementation of JSON Web Tokens: http://self-issued.info/docs/draft-jones-json-web-token.html See README.md for more info.
Go 1.26.1
Constants
const UnsafeAllowNoneSignatureType unsafeNoneMagicConstant = "none signing method allowed"
github.com/golang-jwt/jwt/v5/none.go:7
Variables
var (
// Sadly this is missing from crypto/ecdsa compared to crypto/rsa
ErrECDSAVerification = errors.New("crypto/ecdsa: verification error")
)github.com/golang-jwt/jwt/v5/ecdsa.go:13
var (
ErrEd25519Verification = errors.New("ed25519: verification error")
)github.com/golang-jwt/jwt/v5/ed25519.go:11
var (
ErrInvalidKey = errors.New("key is invalid")
ErrInvalidKeyType = errors.New("key is of invalid type")
ErrHashUnavailable = errors.New("the requested has...github.com/golang-jwt/jwt/v5/errors.go:10
var (
ErrInvalidKey = errors.New("key is invalid")
ErrInvalidKeyType = errors.New("key is of invalid type")
ErrHashUnavailable = errors.New("the requested has...github.com/golang-jwt/jwt/v5/errors.go:11
var (
ErrInvalidKey = errors.New("key is invalid")
ErrInvalidKeyType = errors.New("key is of invalid type")
ErrHashUnavailable = errors.New("the requested has...github.com/golang-jwt/jwt/v5/errors.go:25
var (
ErrKeyMustBePEMEncoded = errors.New("invalid key: Key must be a PEM encoded PKCS1 or PKCS8 key")
ErrNotRSAPrivateKey = errors.New("key is not a valid RSA private key")
ErrNotRSAPublicKe...github.com/golang-jwt/jwt/v5/rsa_utils.go:11
var (
ErrNotECPublicKey = errors.New("key is not a valid ECDSA public key")
ErrNotECPrivateKey = errors.New("key is not a valid ECDSA private key")
)github.com/golang-jwt/jwt/v5/ecdsa_utils.go:12
var (
ErrNotECPublicKey = errors.New("key is not a valid ECDSA public key")
ErrNotECPrivateKey = errors.New("key is not a valid ECDSA private key")
)github.com/golang-jwt/jwt/v5/ecdsa_utils.go:11
var (
ErrNotEdPrivateKey = errors.New("key is not a valid Ed25519 private key")
ErrNotEdPublicKey = errors.New("key is not a valid Ed25519 public key")
)github.com/golang-jwt/jwt/v5/ed25519_utils.go:12
var (
ErrNotEdPrivateKey = errors.New("key is not a valid Ed25519 private key")
ErrNotEdPublicKey = errors.New("key is not a valid Ed25519 public key")
)github.com/golang-jwt/jwt/v5/ed25519_utils.go:13
var (
ErrKeyMustBePEMEncoded = errors.New("invalid key: Key must be a PEM encoded PKCS1 or PKCS8 key")
ErrNotRSAPrivateKey = errors.New("key is not a valid RSA private key")
ErrNotRSAPublicKe...github.com/golang-jwt/jwt/v5/rsa_utils.go:12
var (
ErrKeyMustBePEMEncoded = errors.New("invalid key: Key must be a PEM encoded PKCS1 or PKCS8 key")
ErrNotRSAPrivateKey = errors.New("key is not a valid RSA private key")
ErrNotRSAPublicKe...github.com/golang-jwt/jwt/v5/rsa_utils.go:13
var (
ErrInvalidKey = errors.New("key is invalid")
ErrInvalidKeyType = errors.New("key is of invalid type")
ErrHashUnavailable = errors.New("the requested has...github.com/golang-jwt/jwt/v5/errors.go:18
var (
ErrInvalidKey = errors.New("key is invalid")
ErrInvalidKeyType = errors.New("key is of invalid type")
ErrHashUnavailable = errors.New("the requested has...github.com/golang-jwt/jwt/v5/errors.go:17
var (
ErrInvalidKey = errors.New("key is invalid")
ErrInvalidKeyType = errors.New("key is of invalid type")
ErrHashUnavailable = errors.New("the requested has...github.com/golang-jwt/jwt/v5/errors.go:24
var (
ErrInvalidKey = errors.New("key is invalid")
ErrInvalidKeyType = errors.New("key is of invalid type")
ErrHashUnavailable = errors.New("the requested has...github.com/golang-jwt/jwt/v5/errors.go:23
var (
ErrInvalidKey = errors.New("key is invalid")
ErrInvalidKeyType = errors.New("key is of invalid type")
ErrHashUnavailable = errors.New("the requested has...github.com/golang-jwt/jwt/v5/errors.go:20
var (
ErrInvalidKey = errors.New("key is invalid")
ErrInvalidKeyType = errors.New("key is of invalid type")
ErrHashUnavailable = errors.New("the requested has...github.com/golang-jwt/jwt/v5/errors.go:21
var (
ErrInvalidKey = errors.New("key is invalid")
ErrInvalidKeyType = errors.New("key is of invalid type")
ErrHashUnavailable = errors.New("the requested has...github.com/golang-jwt/jwt/v5/errors.go:13
var (
ErrInvalidKey = errors.New("key is invalid")
ErrInvalidKeyType = errors.New("key is of invalid type")
ErrHashUnavailable = errors.New("the requested has...github.com/golang-jwt/jwt/v5/errors.go:22
var (
ErrInvalidKey = errors.New("key is invalid")
ErrInvalidKeyType = errors.New("key is of invalid type")
ErrHashUnavailable = errors.New("the requested has...github.com/golang-jwt/jwt/v5/errors.go:16
var (
ErrInvalidKey = errors.New("key is invalid")
ErrInvalidKeyType = errors.New("key is of invalid type")
ErrHashUnavailable = errors.New("the requested has...github.com/golang-jwt/jwt/v5/errors.go:15
var (
ErrInvalidKey = errors.New("key is invalid")
ErrInvalidKeyType = errors.New("key is of invalid type")
ErrHashUnavailable = errors.New("the requested has...github.com/golang-jwt/jwt/v5/errors.go:14
var (
ErrInvalidKey = errors.New("key is invalid")
ErrInvalidKeyType = errors.New("key is of invalid type")
ErrHashUnavailable = errors.New("the requested has...github.com/golang-jwt/jwt/v5/errors.go:19
var MarshalSingleStringAsArray = true
MarshalSingleStringAsArray modifies the behavior of the ClaimStrings type, especially its MarshalJSON function. If it is set to true (the default), it will always serialize the type as an array of strings, even if it just contains one element, defaulting to the behavior of the underlying []string. If it is set to false, it will serialize to a single string, if it contains one element. Otherwise, it will serialize to an array of strings.
github.com/golang-jwt/jwt/v5/types.go:28
var NoneSignatureTypeDisallowedError error
github.com/golang-jwt/jwt/v5/none.go:9
var SigningMethodNone *signingMethodNone
SigningMethodNone implements the none signing method. This is required by the spec but you probably should never use it.
github.com/golang-jwt/jwt/v5/none.go:5
var TimePrecision = time.Second
TimePrecision sets the precision of times and dates within this library. This has an influence on the precision of times when comparing expiry or other related time fields. Furthermore, it is also the precision of times when serializing. For backwards compatibility the default precision is set to seconds, so that no fractional timestamps are generated.
github.com/golang-jwt/jwt/v5/types.go:18
Functions
func GetAlgorithms() []string
GetAlgorithms returns a list of registered "alg" names
github.com/golang-jwt/jwt/v5/signing_method.go:41
func GetSigningMethod(alg string) SigningMethod
GetSigningMethod retrieves a signing method from an "alg" string
github.com/golang-jwt/jwt/v5/signing_method.go:30
func New(method SigningMethod, opts ...TokenOption) *Token
New creates a new [Token] with the specified signing method and an empty map of claims. Additional options can be specified, but are currently unused.
github.com/golang-jwt/jwt/v5/token.go:41
func NewNumericDate(t time.Time) *NumericDate
NewNumericDate constructs a new *NumericDate from a standard library time.Time struct. It will truncate the timestamp according to the precision specified in TimePrecision.
github.com/golang-jwt/jwt/v5/types.go:38
func NewParser(options ...ParserOption) *Parser
NewParser creates a new Parser with the specified options
github.com/golang-jwt/jwt/v5/parser.go:31
func NewValidator(opts ...ParserOption) *Validator
NewValidator can be used to create a stand-alone validator with the supplied options. This validator can then be used to validate already parsed claims. Note: Under normal circumstances, explicitly creating a validator is not needed and can potentially be dangerous; instead functions of the [Parser] class should be used. The [Validator] is only checking the *validity* of the claims, such as its expiration time, but it does NOT perform *signature verification* of the token.
github.com/golang-jwt/jwt/v5/validator.go:84
func NewWithClaims(method SigningMethod, claims Claims, opts ...TokenOption) *Token
NewWithClaims creates a new [Token] with the specified signing method and claims. Additional options can be specified, but are currently unused.
github.com/golang-jwt/jwt/v5/token.go:47
func Parse(tokenString string, keyFunc Keyfunc, options ...ParserOption) (*Token, error)
Parse parses, validates, verifies the signature and returns the parsed token. keyFunc will receive the parsed token and should return the cryptographic key for verifying the signature. The caller is strongly encouraged to set the WithValidMethods option to validate the 'alg' claim in the token matches the expected algorithm. For more details about the importance of validating the 'alg' claim, see https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/
github.com/golang-jwt/jwt/v5/parser.go:257
func ParseECPrivateKeyFromPEM(key []byte) (*ecdsa.PrivateKey, error)
ParseECPrivateKeyFromPEM parses a PEM encoded Elliptic Curve Private Key Structure
github.com/golang-jwt/jwt/v5/ecdsa_utils.go:16
func ParseECPublicKeyFromPEM(key []byte) (*ecdsa.PublicKey, error)
ParseECPublicKeyFromPEM parses a PEM encoded PKCS1 or PKCS8 public key
github.com/golang-jwt/jwt/v5/ecdsa_utils.go:43
func ParseEdPrivateKeyFromPEM(key []byte) (crypto.PrivateKey, error)
ParseEdPrivateKeyFromPEM parses a PEM-encoded Edwards curve private key
github.com/golang-jwt/jwt/v5/ed25519_utils.go:17
func ParseEdPublicKeyFromPEM(key []byte) (crypto.PublicKey, error)
ParseEdPublicKeyFromPEM parses a PEM-encoded Edwards curve public key
github.com/golang-jwt/jwt/v5/ed25519_utils.go:42
func ParseRSAPrivateKeyFromPEM(key []byte) (*rsa.PrivateKey, error)
ParseRSAPrivateKeyFromPEM parses a PEM encoded PKCS1 or PKCS8 private key
github.com/golang-jwt/jwt/v5/rsa_utils.go:17
func ParseRSAPrivateKeyFromPEMWithPassword(key []byte, password string) (*rsa.PrivateKey, error)
ParseRSAPrivateKeyFromPEMWithPassword parses a PEM encoded PKCS1 or PKCS8 private key protected with password Deprecated: This function is deprecated and should not be used anymore. It uses the deprecated x509.DecryptPEMBlock function, which was deprecated since RFC 1423 is regarded insecure by design. Unfortunately, there is no alternative in the Go standard library for now. See https://github.com/golang/go/issues/8860.
github.com/golang-jwt/jwt/v5/rsa_utils.go:47
func ParseRSAPublicKeyFromPEM(key []byte) (*rsa.PublicKey, error)
ParseRSAPublicKeyFromPEM parses a certificate or a PEM encoded PKCS1 or PKIX public key
github.com/golang-jwt/jwt/v5/rsa_utils.go:79
func ParseWithClaims(tokenString string, claims Claims, keyFunc Keyfunc, options ...ParserOption) (*Token, error)
ParseWithClaims is a shortcut for NewParser().ParseWithClaims(). Note: If you provide a custom claim implementation that embeds one of the standard claims (such as RegisteredClaims), make sure that a) you either embed a non-pointer version of the claims or b) if you are using a pointer, allocate the proper memory for it before passing in the overall claims, otherwise you might run into a panic.
github.com/golang-jwt/jwt/v5/parser.go:268
func RegisterSigningMethod(alg string, f func(...))
RegisterSigningMethod registers the "alg" name and a factory function for signing method. This is typically done during init() in the method's implementation
github.com/golang-jwt/jwt/v5/signing_method.go:22
func WithAllAudiences(aud ...string) ParserOption
WithAllAudiences configures the validator to require all the specified audiences in the `aud` claim. Validation will fail if the specified audiences are not listed in the token or the `aud` claim is missing. Duplicates within the list are de-duplicated since internally, we use a map to look up the audiences. NOTE: While the `aud` claim is OPTIONAL in a JWT, the handling of it is application-specific. Since this validation API is helping developers in writing secure application, we decided to...
github.com/golang-jwt/jwt/v5/parser_option.go:99
func WithAudience(aud ...string) ParserOption
WithAudience configures the validator to require any of the specified audiences in the `aud` claim. Validation will fail if the audience is not listed in the token or the `aud` claim is missing. NOTE: While the `aud` claim is OPTIONAL in a JWT, the handling of it is application-specific. Since this validation API is helping developers in writing secure application, we decided to REQUIRE the existence of the claim, if an audience is expected.
github.com/golang-jwt/jwt/v5/parser_option.go:83
func WithExpirationRequired() ParserOption
WithExpirationRequired returns the ParserOption to make exp claim required. By default exp claim is optional.
github.com/golang-jwt/jwt/v5/parser_option.go:61
func WithIssuedAt() ParserOption
WithIssuedAt returns the ParserOption to enable verification of issued-at.
github.com/golang-jwt/jwt/v5/parser_option.go:53
func WithIssuer(iss string) ParserOption
WithIssuer configures the validator to require the specified issuer in the `iss` claim. Validation will fail if a different issuer is specified in the token or the `iss` claim is missing. NOTE: While the `iss` claim is OPTIONAL in a JWT, the handling of it is application-specific. Since this validation API is helping developers in writing secure application, we decided to REQUIRE the existence of the claim, if an issuer is expected.
github.com/golang-jwt/jwt/v5/parser_option.go:114
func WithJSONNumber() ParserOption
WithJSONNumber is an option to configure the underlying JSON parser with UseNumber.
github.com/golang-jwt/jwt/v5/parser_option.go:21
func WithLeeway(leeway time.Duration) ParserOption
WithLeeway returns the ParserOption for specifying the leeway window.
github.com/golang-jwt/jwt/v5/parser_option.go:36
func WithNotBeforeRequired() ParserOption
WithNotBeforeRequired returns the ParserOption to make nbf claim required. By default nbf claim is optional.
github.com/golang-jwt/jwt/v5/parser_option.go:69
func WithoutClaimsValidation() ParserOption
WithoutClaimsValidation is an option to disable claims validation. This option should only be used if you exactly know what you are doing.
github.com/golang-jwt/jwt/v5/parser_option.go:29
func WithPaddingAllowed() ParserOption
WithPaddingAllowed will enable the codec used for decoding JWTs to allow padding. Note that the JWS RFC7515 states that the tokens will utilize a Base64url encoding with no padding. Unfortunately, some implementations of JWT are producing non-standard tokens, and thus require support for decoding.
github.com/golang-jwt/jwt/v5/parser_option.go:138
func WithStrictDecoding() ParserOption
WithStrictDecoding will switch the codec used for decoding JWTs into strict mode. In this mode, the decoder requires that trailing padding bits are zero, as described in RFC 4648 section 3.5.
github.com/golang-jwt/jwt/v5/parser_option.go:147
func WithSubject(sub string) ParserOption
WithSubject configures the validator to require the specified subject in the `sub` claim. Validation will fail if a different subject is specified in the token or the `sub` claim is missing. NOTE: While the `sub` claim is OPTIONAL in a JWT, the handling of it is application-specific. Since this validation API is helping developers in writing secure application, we decided to REQUIRE the existence of the claim, if a subject is expected.
github.com/golang-jwt/jwt/v5/parser_option.go:128
func WithTimeFunc(f func(...)) ParserOption
WithTimeFunc returns the ParserOption for specifying the time func. The primary use-case for this is testing. If you are looking for a way to account for clock-skew, WithLeeway should be used instead.
github.com/golang-jwt/jwt/v5/parser_option.go:45
func WithValidMethods(methods []string) ParserOption
WithValidMethods is an option to supply algorithm methods that the parser will check. Only those methods will be considered valid. It is heavily encouraged to use this option in order to prevent attacks such as https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/.
github.com/golang-jwt/jwt/v5/parser_option.go:13
Types
type Claims interface {
GetExpirationTime() (*NumericDate, error)
GetIssuedAt() (*NumericDate, error)
GetNotBefore() (*NumericDate, error)
GetIssuer() (string, error)
GetSubject() (string, err...Claims represent any form of a JWT Claims Set according to https://datatracker.ietf.org/doc/html/rfc7519#section-4. In order to have a common basis for validation, it is required that an implementation is able to supply at least the claim names provided in https://datatracker.ietf.org/doc/html/rfc7519#section-4.1 namely `exp`, `iat`, `nbf`, `iss`, `sub` and `aud`.
github.com/golang-jwt/jwt/v5/claims.go:9
type ClaimStrings []string
ClaimStrings is basically just a slice of strings, but it can be either serialized from a string array or just a string. This type is necessary, since the "aud" claim can either be a single string or an array.
github.com/golang-jwt/jwt/v5/types.go:103
func (s ClaimStrings) MarshalJSON() ([]byte, error)
github.com/golang-jwt/jwt/v5/types.go:138
func (s *ClaimStrings) UnmarshalJSON(data []byte) error
github.com/golang-jwt/jwt/v5/types.go:105
type ClaimsValidator interface {
Claims
Validate() error
}ClaimsValidator is an interface that can be implemented by custom claims who wish to execute any additional claims validation based on application-specific logic. The Validate function is then executed in addition to the regular claims validation and any error returned is appended to the final validation result. type MyCustomClaims struct { Foo string `json:"foo"` jwt.RegisteredClaims } func (m MyCustomClaims) Validate() error { if m.Foo != "bar" { return errors.N...
github.com/golang-jwt/jwt/v5/validator.go:26
type Keyfunc func(*Token) (any, error)
Keyfunc will be used by the Parse methods as a callback function to supply the key for verification. The function receives the parsed, but unverified Token. This allows you to use properties in the Header of the token (such as `kid`) to identify which key to use. The returned any may be a single key or a VerificationKeySet containing multiple keys.
github.com/golang-jwt/jwt/v5/token.go:16
type MapClaims map[string]any
MapClaims is a claims type that uses the map[string]any for JSON decoding. This is the default claims type if you don't supply one
github.com/golang-jwt/jwt/v5/map_claims.go:10
func (m MapClaims) GetAudience() (ClaimStrings, error)
GetAudience implements the Claims interface.
github.com/golang-jwt/jwt/v5/map_claims.go:28
func (m MapClaims) GetExpirationTime() (*NumericDate, error)
GetExpirationTime implements the Claims interface.
github.com/golang-jwt/jwt/v5/map_claims.go:13
func (m MapClaims) GetIssuedAt() (*NumericDate, error)
GetIssuedAt implements the Claims interface.
github.com/golang-jwt/jwt/v5/map_claims.go:23
func (m MapClaims) GetIssuer() (string, error)
GetIssuer implements the Claims interface.
github.com/golang-jwt/jwt/v5/map_claims.go:33
func (m MapClaims) GetNotBefore() (*NumericDate, error)
GetNotBefore implements the Claims interface.
github.com/golang-jwt/jwt/v5/map_claims.go:18
func (m MapClaims) GetSubject() (string, error)
GetSubject implements the Claims interface.
github.com/golang-jwt/jwt/v5/map_claims.go:38
type NumericDate struct {
time.Time
}NumericDate represents a JSON numeric date value, as referenced at https://datatracker.ietf.org/doc/html/rfc7519#section-2.
github.com/golang-jwt/jwt/v5/types.go:32
func (date NumericDate) MarshalJSON() ([]byte, error)
MarshalJSON is an implementation of the json.RawMessage interface and serializes the UNIX epoch represented in NumericDate to a byte array, using the precision specified in TimePrecision.
github.com/golang-jwt/jwt/v5/types.go:51
func (date *NumericDate) UnmarshalJSON(b []byte) error
UnmarshalJSON is an implementation of the json.RawMessage interface and deserializes a [NumericDate] from a JSON representation, i.e. a [json.Number]. This number represents an UNIX epoch with either integer or non-integer seconds.
github.com/golang-jwt/jwt/v5/types.go:80
type Parser struct {
// contains filtered or unexported fields
}github.com/golang-jwt/jwt/v5/parser.go:13
func (p *Parser) DecodeSegment(seg string) ([]byte, error)
DecodeSegment decodes a JWT specific base64url encoding. This function will take into account whether the [Parser] is configured with additional options, such as [WithStrictDecoding] or [WithPaddingAllowed].
github.com/golang-jwt/jwt/v5/parser.go:234
func (p *Parser) Parse(tokenString string, keyFunc Keyfunc) (*Token, error)
Parse parses, validates, verifies the signature and returns the parsed token. keyFunc will receive the parsed token and should return the key for validating.
github.com/golang-jwt/jwt/v5/parser.go:46
func (p *Parser) ParseUnverified(tokenString string, claims Claims) (*Token, []string, error)
ParseUnverified parses the token but does not validate the signature. WARNING: Don't use this method unless you know what you're doing. It's only ever useful in cases where you know the signature is valid (since it has already been or will be checked elsewhere in the stack) and you want to extract values from it.
github.com/golang-jwt/jwt/v5/parser.go:136
func (p *Parser) ParseWithClaims(tokenString string, claims Claims, keyFunc Keyfunc) (*Token, error)
ParseWithClaims parses, validates, and verifies like Parse, but supplies a default object implementing the Claims interface. This provides default values which can be overridden and allows a caller to use their own type, rather than the default MapClaims implementation of Claims. Note: If you provide a custom claim implementation that embeds one of the standard claims (such as RegisteredClaims), make sure that a) you either embed a non-pointer version of the claims or b) if you are using a p...
github.com/golang-jwt/jwt/v5/parser.go:57
type ParserOption func(*Parser)
ParserOption is used to implement functional-style options that modify the behavior of the parser.
github.com/golang-jwt/jwt/v5/parser_option.go:7
type RegisteredClaims struct {
// the `iss` (Issuer) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.1
Issuer string `json:"iss,omitempty"`
// the `sub` (Subject) claim. Se...RegisteredClaims are a structured version of the JWT Claims Set, restricted to Registered Claim Names, as referenced at https://datatracker.ietf.org/doc/html/rfc7519#section-4.1 This type can be used on its own, but then additional private and public claims embedded in the JWT will not be parsed. The typical use-case therefore is to embedded this in a user-defined claim type. See examples for how to use this with your own claim types.
github.com/golang-jwt/jwt/v5/registered_claims.go:12
func (c RegisteredClaims) GetAudience() (ClaimStrings, error)
GetAudience implements the Claims interface.
github.com/golang-jwt/jwt/v5/registered_claims.go:51
func (c RegisteredClaims) GetExpirationTime() (*NumericDate, error)
GetExpirationTime implements the Claims interface.
github.com/golang-jwt/jwt/v5/registered_claims.go:36
func (c RegisteredClaims) GetIssuedAt() (*NumericDate, error)
GetIssuedAt implements the Claims interface.
github.com/golang-jwt/jwt/v5/registered_claims.go:46
func (c RegisteredClaims) GetIssuer() (string, error)
GetIssuer implements the Claims interface.
github.com/golang-jwt/jwt/v5/registered_claims.go:56
func (c RegisteredClaims) GetNotBefore() (*NumericDate, error)
GetNotBefore implements the Claims interface.
github.com/golang-jwt/jwt/v5/registered_claims.go:41
func (c RegisteredClaims) GetSubject() (string, error)
GetSubject implements the Claims interface.
github.com/golang-jwt/jwt/v5/registered_claims.go:61
type SigningMethod interface {
Verify(signingString string, sig []byte, key any) error // Returns nil if signature is valid
Sign(signingString string, key any) ([]byte, error) // Returns sign...SigningMethod can be used add new methods for signing or verifying tokens. It takes a decoded signature as an input in the Verify function and produces a signature in Sign. The signature is then usually base64 encoded as part of a JWT.
github.com/golang-jwt/jwt/v5/signing_method.go:14
type SigningMethodECDSA struct {
Name string
Hash crypto.Hash
KeySize int
CurveBits int
}SigningMethodECDSA implements the ECDSA family of signing methods. Expects *ecdsa.PrivateKey for signing and *ecdsa.PublicKey for verification
github.com/golang-jwt/jwt/v5/ecdsa.go:18
func (m *SigningMethodECDSA) Alg() string
github.com/golang-jwt/jwt/v5/ecdsa.go:52
func (m *SigningMethodECDSA) Sign(signingString string, key any) ([]byte, error)
Sign implements token signing for the SigningMethod. For this signing method, key must be an ecdsa.PrivateKey struct
github.com/golang-jwt/jwt/v5/ecdsa.go:92
func (m *SigningMethodECDSA) Verify(signingString string, sig []byte, key any) error
Verify implements token verification for the SigningMethod. For this verify method, key must be an ecdsa.PublicKey struct
github.com/golang-jwt/jwt/v5/ecdsa.go:58
type SigningMethodEd25519 struct{}SigningMethodEd25519 implements the EdDSA family. Expects ed25519.PrivateKey for signing and ed25519.PublicKey for verification
github.com/golang-jwt/jwt/v5/ed25519.go:16
func (m *SigningMethodEd25519) Alg() string
github.com/golang-jwt/jwt/v5/ed25519.go:30
func (m *SigningMethodEd25519) Sign(signingString string, key any) ([]byte, error)
Sign implements token signing for the SigningMethod. For this signing method, key must be an ed25519.PrivateKey
github.com/golang-jwt/jwt/v5/ed25519.go:58
func (m *SigningMethodEd25519) Verify(signingString string, sig []byte, key any) error
Verify implements token verification for the SigningMethod. For this verify method, key must be an ed25519.PublicKey
github.com/golang-jwt/jwt/v5/ed25519.go:36
type SigningMethodHMAC struct {
Name string
Hash crypto.Hash
}SigningMethodHMAC implements the HMAC-SHA family of signing methods. Expects key type of []byte for both signing and validation
github.com/golang-jwt/jwt/v5/hmac.go:11
func (m *SigningMethodHMAC) Alg() string
github.com/golang-jwt/jwt/v5/hmac.go:44
func (m *SigningMethodHMAC) Sign(signingString string, key any) ([]byte, error)
Sign implements token signing for the SigningMethod. Key must be []byte. Note it is not advised to provide a []byte which was converted from a 'human readable' string using a subset of ASCII characters. To maximize entropy, you should ideally be providing a []byte key which was produced from a cryptographically random source, e.g. crypto/rand. Additional information about this, and why we intentionally are not supporting string as a key can be found on our usage guide https://golang-jwt.gith...
github.com/golang-jwt/jwt/v5/hmac.go:91
func (m *SigningMethodHMAC) Verify(signingString string, sig []byte, key any) error
Verify implements token verification for the SigningMethod. Returns nil if the signature is valid. Key must be []byte. Note it is not advised to provide a []byte which was converted from a 'human readable' string using a subset of ASCII characters. To maximize entropy, you should ideally be providing a []byte key which was produced from a cryptographically random source, e.g. crypto/rand. Additional information about this, and why we intentionally are not supporting string as a key can be fo...
github.com/golang-jwt/jwt/v5/hmac.go:58
type SigningMethodRSA struct {
Name string
Hash crypto.Hash
}SigningMethodRSA implements the RSA family of signing methods. Expects *rsa.PrivateKey for signing and *rsa.PublicKey for validation
github.com/golang-jwt/jwt/v5/rsa.go:11
func (m *SigningMethodRSA) Alg() string
github.com/golang-jwt/jwt/v5/rsa.go:43
func (m *SigningMethodRSA) Sign(signingString string, key any) ([]byte, error)
Sign implements token signing for the SigningMethod For this signing method, must be an *rsa.PrivateKey structure.
github.com/golang-jwt/jwt/v5/rsa.go:70
func (m *SigningMethodRSA) Verify(signingString string, sig []byte, key any) error
Verify implements token verification for the SigningMethod For this signing method, must be an *rsa.PublicKey structure.
github.com/golang-jwt/jwt/v5/rsa.go:49
type SigningMethodRSAPSS struct {
*SigningMethodRSA
Options *rsa.PSSOptions
// VerifyOptions is optional. If set overrides Options for rsa.VerifyPPS.
// Used to accept tokens signed with rsa.PS...SigningMethodRSAPSS implements the RSAPSS family of signing methods signing methods
github.com/golang-jwt/jwt/v5/rsa_pss.go:10
func (m *SigningMethodRSAPSS) Sign(signingString string, key any) ([]byte, error)
Sign implements token signing for the SigningMethod. For this signing method, key must be an rsa.PrivateKey struct
github.com/golang-jwt/jwt/v5/rsa_pss.go:108
func (m *SigningMethodRSAPSS) Verify(signingString string, sig []byte, key any) error
Verify implements token verification for the SigningMethod. For this verify method, key must be an rsa.PublicKey struct
github.com/golang-jwt/jwt/v5/rsa_pss.go:82
type Token struct {
Raw string // Raw contains the raw token. Populated when you [Parse] a token
Method SigningMethod // Method is the signing method used or to be used
Header...Token represents a JWT Token. Different fields will be used depending on whether you're creating or parsing/verifying a token.
github.com/golang-jwt/jwt/v5/token.go:30
func (*Token) EncodeSegment(seg []byte) string
EncodeSegment encodes a JWT specific base64url encoding with padding stripped. In the future, this function might take into account a [TokenOption]. Therefore, this function exists as a method of [Token], rather than a global function.
github.com/golang-jwt/jwt/v5/token.go:100
func (t *Token) SignedString(key any) (string, error)
SignedString creates and returns a complete, signed JWT. The token is signed using the SigningMethod specified in the token. Please refer to https://golang-jwt.github.io/jwt/usage/signing_methods/#signing-methods-and-key-types for an overview of the different signing methods and their respective key types.
github.com/golang-jwt/jwt/v5/token.go:63
func (t *Token) SigningString() (string, error)
SigningString generates the signing string. This is the most expensive part of the whole deal. Unless you need this for something special, just go straight for the SignedString.
github.com/golang-jwt/jwt/v5/token.go:82
type TokenOption func(*Token)
TokenOption is a reserved type, which provides some forward compatibility, if we ever want to introduce token creation-related options.
github.com/golang-jwt/jwt/v5/token_option.go:5
type Validator struct {
// contains filtered or unexported fields
}Validator is the core of the new Validation API. It is automatically used by a [Parser] during parsing and can be modified with various parser options. The [NewValidator] function should be used to create an instance of this struct.
github.com/golang-jwt/jwt/v5/validator.go:36
func (v *Validator) Validate(claims Claims) error
Validate validates the given claims. It will also perform any custom validation if claims implements the [ClaimsValidator] interface. Note: It will NOT perform any *signature verification* on the token that contains the claims and expects that the [Claim] was already successfully verified.
github.com/golang-jwt/jwt/v5/validator.go:95
type VerificationKey interface {
crypto.PublicKey | []uint8
}VerificationKey represents a public or secret key for verifying a token's signature.
github.com/golang-jwt/jwt/v5/token.go:19
type VerificationKeySet struct {
Keys []VerificationKey
}VerificationKeySet is a set of public or secret keys. It is used by the parser to verify a token.
github.com/golang-jwt/jwt/v5/token.go:24