Documentation
¶
Index ¶
- Constants
- Variables
- func GetSigningMethod(alg string) (method any)
- func GetSigningMethodAlgs() (algs []string)
- func NewError(message string, err error, more ...error) error
- func ParseECPrivateKeyFromDer(der []byte) (*ecdsa.PrivateKey, error)
- func ParseECPublicKeyFromDer(der []byte) (*ecdsa.PublicKey, error)
- func ParseEdPrivateKeyFromDer(der []byte) (ed25519.PrivateKey, error)
- func ParseEdPublicKeyFromDer(der []byte) (ed25519.PublicKey, error)
- func ParsePEM(data []byte) ([]byte, error)
- func ParseRSAPrivateKeyFromDer(der []byte) (*rsa.PrivateKey, error)
- func ParseRSAPublicKeyFromDer(der []byte) (*rsa.PublicKey, error)
- func RegisterSigningMethod(alg string, f func() any)
- type Builder
- func (b *Builder[S]) CanOnlyBeUsedAfter(notBefore *NumericDate) *Builder[S]
- func (b *Builder[S]) ExpiresAt(expiration *NumericDate) *Builder[S]
- func (b *Builder[S]) GetToken(key S) (*Token, error)
- func (b *Builder[S]) HeaderAlgo(value any) *Builder[S]
- func (b *Builder[S]) HeaderType(value any) *Builder[S]
- func (b *Builder[S]) IdentifiedBy(id string) *Builder[S]
- func (b *Builder[S]) IssuedAt(issuedAt *NumericDate) *Builder[S]
- func (b *Builder[S]) IssuedBy(issuer string) *Builder[S]
- func (b *Builder[S]) PermittedFor(audiences ClaimStrings) *Builder[S]
- func (b *Builder[S]) RelatedTo(subject string) *Builder[S]
- func (b *Builder[S]) WithClaim(name string, value any) *Builder[S]
- func (b *Builder[S]) WithHeader(name string, value any) *Builder[S]
- type ClaimStrings
- type Claims
- type IEncoder
- type ISignAlgo
- type ISigner
- type ISigning
- type IVerifying
- type JWT
- func (jwt *JWT[S, V]) Alg() string
- func (jwt *JWT[S, V]) Build() *Builder[S]
- func (jwt JWT[S, V]) New() *JWT[S, V]
- func (jwt *JWT[S, V]) Parse(tokenString string, verifyKey V) (*Token, error)
- func (jwt *JWT[S, V]) Sign(claims any, signKey S) (string, error)
- func (jwt *JWT[S, V]) SignLength() int
- func (jwt *JWT[S, V]) SignWithHeader(header any, claims any, signKey S) (string, error)
- func (jwt *JWT[S, V]) WithEncoder(encoder IEncoder) *JWT[S, V]
- type MapClaims
- func (m MapClaims) GetAudience() (ClaimStrings, error)
- func (m MapClaims) GetClaimsString(name string) (ClaimStrings, error)
- func (m MapClaims) GetExpirationTime() (*NumericDate, error)
- func (m MapClaims) GetIssuedAt() (*NumericDate, error)
- func (m MapClaims) GetIssuer() (string, error)
- func (m MapClaims) GetNotBefore() (*NumericDate, error)
- func (m MapClaims) GetNumericDate(name string) (*NumericDate, error)
- func (m MapClaims) GetString(name string) (string, error)
- func (m MapClaims) GetSubject() (string, error)
- type NumericDate
- type ParserOption
- type RegisteredClaims
- func (c RegisteredClaims) GetAudience() (ClaimStrings, error)
- func (c RegisteredClaims) GetExpirationTime() (*NumericDate, error)
- func (c RegisteredClaims) GetIssuedAt() (*NumericDate, error)
- func (c RegisteredClaims) GetIssuer() (string, error)
- func (c RegisteredClaims) GetNotBefore() (*NumericDate, error)
- func (c RegisteredClaims) GetSubject() (string, error)
- type SignBlake2b
- type SignECDSA
- type SignEdDSA
- type SignHmac
- type SignNone
- type SignRSA
- type SignRSAPSS
- type Token
- func (t *Token) GetClaims() (MapClaims, error)
- func (t *Token) GetClaimsT(dst any) error
- func (t *Token) GetHeader() (TokenHeader, error)
- func (t *Token) GetHeaders() (map[string]string, error)
- func (t *Token) GetHeadersT(dst any) error
- func (t *Token) GetMsg() string
- func (t *Token) GetPartCount() int
- func (t *Token) GetRaw() string
- func (t *Token) GetSignature() []byte
- func (t *Token) Parse(tokenString string)
- func (t *Token) SetClaims(claims any) error
- func (t *Token) SetHeader(header any) error
- func (t *Token) SignedString() (string, error)
- func (t *Token) SigningString() (string, error)
- func (t *Token) WithClaims(claims []byte)
- func (t *Token) WithHeader(header []byte)
- func (t *Token) WithSignature(signature []byte)
- type TokenHeader
- type Validator
- func (v *Validator) HasBeenIssuedBefore(now int64) bool
- func (v *Validator) HasBeenIssuedBy(issuer string) bool
- func (v *Validator) IsExpired(now int64) bool
- func (v *Validator) IsIdentifiedBy(id string) bool
- func (v *Validator) IsMinimumTimeBefore(now int64) bool
- func (v *Validator) IsPermittedFor(audience string) bool
- func (v *Validator) IsRelatedTo(subject string) bool
- func (v *Validator) WithLeeway(leeway int64) *Validator
Constants ¶
const ( // Defines the list of headers that are registered in the IANA "JSON Web Token Headers" registry RegisteredHeadersType = "typ" RegisteredHeadersAlgorithm = "alg" RegisteredHeadersEncryption = "enc" // Defines the list of claims that are registered in the IANA "JSON Web Token Claims" registry RegisteredClaimsAudience = "aud" RegisteredClaimsExpirationTime = "exp" RegisteredClaimsID = "jti" RegisteredClaimsIssuedAt = "iat" RegisteredClaimsIssuer = "iss" RegisteredClaimsNotBefore = "nbf" RegisteredClaimsSubject = "sub" )
const MaxModulusLen = 512
const Version = "1.0.10021"
Variables ¶
var ( ErrVerifyKeyTooShort = errors.New("go-jwt: SignBlake2b key too short") ErrSignBlake2bVerifyFail = errors.New("go-jwt: SignBlake2b Verify fail") )
var ( SigningES256 = NewSignECDSA(crypto.SHA256, 32, "ES256") SigningES384 = NewSignECDSA(crypto.SHA384, 48, "ES384") SigningES512 = NewSignECDSA(crypto.SHA512, 66, "ES512") )
var ( ErrSignECDSASignLengthInvalid = errors.New("go-jwt: sign length error") ErrSignECDSAVerifyFail = errors.New("go-jwt: SignECDSA Verify fail") )
var ( ErrNotECPublicKey = errors.New("go-jwt: key is not a valid ECDSA public key") ErrNotECPrivateKey = errors.New("go-jwt: key is not a valid ECDSA private key") )
var ( SigningEdDSA = NewSignEdDSA("EdDSA") SigningED25519 = NewSignEdDSA("ED25519") )
var ( ErrSignEdDSASignLengthInvalid = errors.New("go-jwt: sign length error") ErrSignEdDSAVerifyFail = errors.New("go-jwt: SignEdDSA Verify fail") )
var ( ErrNotEdPrivateKey = errors.New("go-jwt: key is not a valid Ed25519 private key") ErrNotEdPublicKey = errors.New("go-jwt: key is not a valid Ed25519 public key") )
var ( SigningHMD5 = NewSignHmac(md5.New, "HMD5") SigningHSHA1 = NewSignHmac(sha1.New, "HSHA1") SigningHS224 = NewSignHmac(sha256.New224, "HS224") SigningHS256 = NewSignHmac(sha256.New, "HS256") SigningHS384 = NewSignHmac(sha512.New384, "HS384") SigningHS512 = NewSignHmac(sha512.New, "HS512") )
var ( // Hmac SigningMethodHMD5 = NewJWT[[]byte, []byte](SigningHMD5, JWTEncoder) SigningMethodHSHA1 = NewJWT[[]byte, []byte](SigningHSHA1, JWTEncoder) SigningMethodHS224 = NewJWT[[]byte, []byte](SigningHS224, JWTEncoder) SigningMethodHS256 = NewJWT[[]byte, []byte](SigningHS256, JWTEncoder) SigningMethodHS384 = NewJWT[[]byte, []byte](SigningHS384, JWTEncoder) SigningMethodHS512 = NewJWT[[]byte, []byte](SigningHS512, JWTEncoder) // RSA SigningMethodRS256 = NewJWT[*rsa.PrivateKey, *rsa.PublicKey](SigningRS256, JWTEncoder) SigningMethodRS384 = NewJWT[*rsa.PrivateKey, *rsa.PublicKey](SigningRS384, JWTEncoder) SigningMethodRS512 = NewJWT[*rsa.PrivateKey, *rsa.PublicKey](SigningRS512, JWTEncoder) // RSA-PSS SigningMethodPS256 = NewJWT[*rsa.PrivateKey, *rsa.PublicKey](SigningPS256, JWTEncoder) SigningMethodPS384 = NewJWT[*rsa.PrivateKey, *rsa.PublicKey](SigningPS384, JWTEncoder) SigningMethodPS512 = NewJWT[*rsa.PrivateKey, *rsa.PublicKey](SigningPS512, JWTEncoder) // ECDSA SigningMethodES256 = NewJWT[*ecdsa.PrivateKey, *ecdsa.PublicKey](SigningES256, JWTEncoder) SigningMethodES384 = NewJWT[*ecdsa.PrivateKey, *ecdsa.PublicKey](SigningES384, JWTEncoder) SigningMethodES512 = NewJWT[*ecdsa.PrivateKey, *ecdsa.PublicKey](SigningES512, JWTEncoder) // EdDSA SigningMethodEdDSA = NewJWT[ed25519.PrivateKey, ed25519.PublicKey](SigningEdDSA, JWTEncoder) SigningMethodED25519 = NewJWT[ed25519.PrivateKey, ed25519.PublicKey](SigningED25519, JWTEncoder) // Blake2b SigningMethodBLAKE2B = NewJWT[[]byte, []byte](SigningBLAKE2B, JWTEncoder) // None SigningMethodNone = NewJWT[[]byte, []byte](SigningNone, JWTEncoder) )
var ( ErrJWTInvalidType = errors.New("go-jwt: invalid type for claim") ErrJWTSignerInvalid = errors.New("go-jwt: Signer invalid") ErrJWTEncoderInvalid = errors.New("go-jwt: Encoder invalid") ErrJWTTokenInvalid = errors.New("go-jwt: Token invalid") ErrJWTTypeInvalid = errors.New("go-jwt: Type invalid") ErrJWTAlgoInvalid = errors.New("go-jwt: Algo invalid") ErrJWTTokenSignatureInvalid = errors.New("go-jwt: token signature is invalid") ErrJWTMethodExists = errors.New("go-jwt: Method not exists") ErrJWTMethodInvalid = errors.New("go-jwt: Method invalid") ErrJWTVerifyFail = errors.New("go-jwt: Verify fail") )
var ( SigningRS256 = NewSignRSA(crypto.SHA256, "RS256") SigningRS384 = NewSignRSA(crypto.SHA384, "RS384") SigningRS512 = NewSignRSA(crypto.SHA512, "RS512") )
var ( SigningPS256 = NewSignRSAPSS(crypto.SHA256, &rsa.PSSOptions{ SaltLength: rsa.PSSSaltLengthEqualsHash, }, &rsa.PSSOptions{ SaltLength: rsa.PSSSaltLengthAuto, }, "PS256") SigningPS384 = NewSignRSAPSS(crypto.SHA384, &rsa.PSSOptions{ SaltLength: rsa.PSSSaltLengthEqualsHash, }, &rsa.PSSOptions{ SaltLength: rsa.PSSSaltLengthAuto, }, "PS384") SigningPS512 = NewSignRSAPSS(crypto.SHA512, &rsa.PSSOptions{ SaltLength: rsa.PSSSaltLengthEqualsHash, }, &rsa.PSSOptions{ SaltLength: rsa.PSSSaltLengthAuto, }, "PS512") )
var ( ErrNotRSAPrivateKey = errors.New("go-jwt: key is not a valid RSA private key") ErrNotRSAPublicKey = errors.New("go-jwt: key is not a valid RSA public key") )
var ErrPEMInvalid = errors.New("go-jwt: PEM parse invalid")
var ErrSignHmacVerifyFail = errors.New("go-jwt: SignHmac Verify fail")
var ErrSignNoneSignatureInvalid = errors.New("go-jwt: SignNone verify signature not empty")
var JWTEncoder = encoder.NewJoseEncoder()
jwt default encoder
var JWTParserOption = ParserOption{ Encoder: JWTEncoder, }
default ParserOption
var JWTStrictEncoder = encoder.NewJoseEncoder(encoder.WithStrictDecoding())
jwt encoder for strict decoding
var (
SigningBLAKE2B = NewSignBlake2b(blake2b.New256, "BLAKE2B")
)
var (
SigningNone = NewSignNone("none")
)
var TimePrecision = time.Second
TimePrecision sets the precision of times and dates within this library.
Functions ¶
func GetSigningMethod ¶ added in v1.0.10007
GetSigningMethod retrieves a signing method from an "alg" string
func GetSigningMethodAlgs ¶ added in v1.0.10007
func GetSigningMethodAlgs() (algs []string)
GetSigningMethodAlgs returns a list of registered "alg" names
func NewError ¶ added in v1.0.10015
NewError creates a new error message with a detailed error message.
func ParseECPrivateKeyFromDer ¶
func ParseECPrivateKeyFromDer(der []byte) (*ecdsa.PrivateKey, error)
ParseECPrivateKeyFromDer parses a PEM encoded Elliptic Curve Private Key Structure
func ParseECPublicKeyFromDer ¶
ParseECPublicKeyFromDer parses a PEM encoded PKCS1 or PKCS8 public key
func ParseEdPrivateKeyFromDer ¶
func ParseEdPrivateKeyFromDer(der []byte) (ed25519.PrivateKey, error)
ParseEdPrivateKeyFromDer parses a PEM-encoded Edwards curve private key
func ParseEdPublicKeyFromDer ¶
ParseEdPublicKeyFromDer parses a PEM-encoded Edwards curve public key
func ParseRSAPrivateKeyFromDer ¶
func ParseRSAPrivateKeyFromDer(der []byte) (*rsa.PrivateKey, error)
ParseRSAPrivateKeyFromDer parses a PEM encoded PKCS1 or PKCS8 private key
func ParseRSAPublicKeyFromDer ¶
ParseRSAPublicKeyFromDer parses a PEM encoded PKCS1 or PKCS8 public key
func RegisterSigningMethod ¶ added in v1.0.10007
RegisterSigningMethod registers the "alg" name and a factory function for signing method.
Types ¶
type Builder ¶ added in v1.0.10011
type Builder[S any] struct { // contains filtered or unexported fields }
This class makes easier the token creation process
func NewBuilder ¶ added in v1.0.10011
func (*Builder[S]) CanOnlyBeUsedAfter ¶ added in v1.0.10011
func (b *Builder[S]) CanOnlyBeUsedAfter(notBefore *NumericDate) *Builder[S]
Configures the time before which the token cannot be accepted
func (*Builder[S]) ExpiresAt ¶ added in v1.0.10011
func (b *Builder[S]) ExpiresAt(expiration *NumericDate) *Builder[S]
Configures the expiration time, expirTime
func (*Builder[S]) HeaderAlgo ¶ added in v1.0.10011
Configures the header algorithm
func (*Builder[S]) HeaderType ¶ added in v1.0.10011
Configures the header type
func (*Builder[S]) IdentifiedBy ¶ added in v1.0.10011
Configures the token id JwtId
func (*Builder[S]) IssuedAt ¶ added in v1.0.10011
func (b *Builder[S]) IssuedAt(issuedAt *NumericDate) *Builder[S]
Configures the time that the token was issued
func (*Builder[S]) PermittedFor ¶ added in v1.0.10011
func (b *Builder[S]) PermittedFor(audiences ClaimStrings) *Builder[S]
Configures the audience
type ClaimStrings ¶ added in v1.0.10008
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.
func NewClaimSingleString ¶ added in v1.0.10010
func NewClaimSingleString(val string) ClaimStrings
NewClaimSingleString constructs a new ClaimStrings.
func NewClaimStringArray ¶ added in v1.0.10010
func NewClaimStringArray(val []string) ClaimStrings
NewClaimStringArray constructs a new ClaimStrings.
func NewClaimStrings ¶ added in v1.0.10010
func NewClaimStrings(val []string, asString bool) ClaimStrings
NewClaimStrings constructs a new ClaimStrings.
func (ClaimStrings) MarshalJSON ¶ added in v1.0.10008
func (s ClaimStrings) MarshalJSON() (b []byte, err error)
func (*ClaimStrings) UnmarshalJSON ¶ added in v1.0.10008
func (s *ClaimStrings) UnmarshalJSON(data []byte) (err error)
type Claims ¶ added in v1.0.10008
type Claims interface {
GetExpirationTime() (*NumericDate, error)
GetIssuedAt() (*NumericDate, error)
GetNotBefore() (*NumericDate, error)
GetIssuer() (string, error)
GetSubject() (string, error)
GetAudience() (ClaimStrings, error)
}
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`.
type IEncoder ¶
type IEncoder interface {
// Base64URL Encode function
Base64URLEncode(data []byte) (string, error)
// Base64URL Decode function
Base64URLDecode(data string) ([]byte, error)
// JSON Encode function
JSONEncode(data any) ([]byte, error)
// JSON Decode function
JSONDecode(data []byte, dst any) error
}
jwt encoder driver interface
type ISigner ¶
type ISigner[S any, V any] interface { ISignAlgo // sign function Sign(msg []byte, signKey S) ([]byte, error) // verify function Verify(msg []byte, signature []byte, verifyKey V) (bool, error) }
jwt singer driver interface
type ISigning ¶ added in v1.0.10019
type ISigning[S any] interface { ISignAlgo // sign function Sign(msg []byte, signKey S) ([]byte, error) }
jwt singing driver interface
type IVerifying ¶ added in v1.0.10019
type IVerifying[V any] interface { ISignAlgo // verify function Verify(msg []byte, signature []byte, verifyKey V) (bool, error) }
jwt verifying driver interface
type JWT ¶
func (*JWT[S, V]) SignWithHeader ¶
SignWithHeader implements token signing for the Signer.
func (*JWT[S, V]) WithEncoder ¶
with new encoder
type MapClaims ¶ added in v1.0.10007
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
func (MapClaims) GetAudience ¶ added in v1.0.10007
func (m MapClaims) GetAudience() (ClaimStrings, error)
GetAudience implements the Claims interface.
func (MapClaims) GetClaimsString ¶ added in v1.0.10008
func (m MapClaims) GetClaimsString(name string) (ClaimStrings, error)
GetClaimsString implements the Claims interface.
func (MapClaims) GetExpirationTime ¶ added in v1.0.10007
func (m MapClaims) GetExpirationTime() (*NumericDate, error)
GetExpirationTime implements the Claims interface.
func (MapClaims) GetIssuedAt ¶ added in v1.0.10007
func (m MapClaims) GetIssuedAt() (*NumericDate, error)
GetIssuedAt implements the Claims interface.
func (MapClaims) GetNotBefore ¶ added in v1.0.10007
func (m MapClaims) GetNotBefore() (*NumericDate, error)
GetNotBefore implements the Claims interface.
func (MapClaims) GetNumericDate ¶ added in v1.0.10007
func (m MapClaims) GetNumericDate(name string) (*NumericDate, error)
GetNumericDate implements the Claims interface.
func (MapClaims) GetSubject ¶ added in v1.0.10007
GetSubject implements the Claims interface.
type NumericDate ¶ added in v1.0.10007
NumericDate represents a JSON numeric date value, as referenced at https://datatracker.ietf.org/doc/html/rfc7519#section-2.
func NewNumericDate ¶ added in v1.0.10007
func NewNumericDate(t time.Time) *NumericDate
NewNumericDate constructs a new *NumericDate from a standard library time.Time struct.
func (NumericDate) MarshalJSON ¶ added in v1.0.10008
func (date NumericDate) MarshalJSON() (b []byte, err 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.
func (*NumericDate) UnmarshalJSON ¶ added in v1.0.10008
func (date *NumericDate) UnmarshalJSON(b []byte) (err 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.
type ParserOption ¶ added in v1.0.10013
type ParserOption struct {
// jwt encoder
Encoder IEncoder
// jwt valid methods
ValidMethods []string
}
jwt ParserOption for Parse function
type RegisteredClaims ¶ added in v1.0.10008
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. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.2
Subject string `json:"sub,omitempty"`
// the `aud` (Audience) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.3
Audience ClaimStrings `json:"aud,omitempty"`
// the `exp` (Expiration Time) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.4
ExpiresAt *NumericDate `json:"exp,omitempty"`
// the `nbf` (Not Before) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.5
NotBefore *NumericDate `json:"nbf,omitempty"`
// the `iat` (Issued At) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.6
IssuedAt *NumericDate `json:"iat,omitempty"`
// the `jti` (JWT ID) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.7
ID string `json:"jti,omitempty"`
}
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
func (RegisteredClaims) GetAudience ¶ added in v1.0.10008
func (c RegisteredClaims) GetAudience() (ClaimStrings, error)
GetAudience implements the Claims interface.
func (RegisteredClaims) GetExpirationTime ¶ added in v1.0.10008
func (c RegisteredClaims) GetExpirationTime() (*NumericDate, error)
GetExpirationTime implements the Claims interface.
func (RegisteredClaims) GetIssuedAt ¶ added in v1.0.10008
func (c RegisteredClaims) GetIssuedAt() (*NumericDate, error)
GetIssuedAt implements the Claims interface.
func (RegisteredClaims) GetIssuer ¶ added in v1.0.10008
func (c RegisteredClaims) GetIssuer() (string, error)
GetIssuer implements the Claims interface.
func (RegisteredClaims) GetNotBefore ¶ added in v1.0.10008
func (c RegisteredClaims) GetNotBefore() (*NumericDate, error)
GetNotBefore implements the Claims interface.
func (RegisteredClaims) GetSubject ¶ added in v1.0.10008
func (c RegisteredClaims) GetSubject() (string, error)
GetSubject implements the Claims interface.
type SignBlake2b ¶
SignBlake2b implements signing methods.
func NewSignBlake2b ¶
type SignECDSA ¶
SignECDSA implements the ECDSA family of signing methods.
type SignEdDSA ¶
type SignEdDSA struct {
Name string
}
SignEdDSA implements the EdDSA family of signing methods.
func NewSignEdDSA ¶
type SignHmac ¶
SignHmac implements the Hmac family of signing methods.
type SignNone ¶
type SignNone struct {
Name string
}
SignNone implements signing methods.
func NewSignNone ¶
type SignRSA ¶
SignRSA implements the RSA family of signing methods.
func (*SignRSA) SignLength ¶
Signer signed bytes length. rsa sign size can get from rsa.PrivateKey.Size()
type SignRSAPSS ¶ added in v1.0.10007
type SignRSAPSS struct {
Name string
Hash crypto.Hash
Options *rsa.PSSOptions
VerifyOptions *rsa.PSSOptions
}
SignRSA implements the RSA family of signing methods.
func NewSignRSAPSS ¶ added in v1.0.10007
func NewSignRSAPSS( hash crypto.Hash, options *rsa.PSSOptions, verifyOptions *rsa.PSSOptions, name string, ) *SignRSAPSS
func (*SignRSAPSS) Sign ¶ added in v1.0.10007
func (s *SignRSAPSS) Sign(msg []byte, key *rsa.PrivateKey) ([]byte, error)
Sign implements token signing for the Signer.
func (*SignRSAPSS) SignLength ¶ added in v1.0.10007
func (s *SignRSAPSS) SignLength() int
Signer signed bytes length. rsa sign size can get from rsa.PrivateKey.Size()
type Token ¶
type Token struct {
// contains filtered or unexported fields
}
Token represents a JWT Token.
func Parse ¶ added in v1.0.10007
func Parse[V any](tokenString string, key V, opt ...ParserOption) (*Token, error)
Parse parses the signature and returns the parsed token.
func (*Token) GetClaimsT ¶
return token claims with custom type
func (*Token) GetHeader ¶
func (t *Token) GetHeader() (TokenHeader, error)
return token TokenHeader struct
func (*Token) GetHeaders ¶ added in v1.0.10001
return token header map
func (*Token) GetHeadersT ¶ added in v1.0.10001
return token header with custom type
func (*Token) GetPartCount ¶ added in v1.0.10011
return token string part count
func (*Token) SignedString ¶
SignedString creates and returns a complete, signed JWT.
func (*Token) SigningString ¶
SigningString generates the signing string.
type TokenHeader ¶
type TokenHeader struct {
Typ string `json:"typ"`
Alg string `json:"alg"`
Kid string `json:"kid,omitempty"`
}
Token Header data.
func GetTokenHeader ¶
func GetTokenHeader(tokenString string, encoder ...IEncoder) (TokenHeader, error)
get token header from token string
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
jwt token validator