Documentation ¶
Overview ¶
Package jwt all in one JWT sdk
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // SignMethodHS256 use HS256 for jwt SignMethodHS256 = jwt.SigningMethodHS256 // SignMethodES256 use ES256 for jwt SignMethodES256 = jwt.SigningMethodES256 // SignMethodRS256 use RSA-256 for jwt SignMethodRS256 = jwt.SigningMethodRS256 )
Functions ¶
func ParseTokenWithoutValidate ¶
ParseTokenWithoutValidate parse and get payload without validate jwt token
Types ¶
type DivideOption ¶
type DivideOption func(*divideOpt) error
DivideOption options to use separate secret for every user in parsing/signing
func WithDividePriKey ¶
func WithDividePriKey(priKey []byte) DivideOption
WithDividePriKey set asymmetrical private key for each signning/verify
func WithDividePubKey ¶
func WithDividePubKey(pubKey []byte) DivideOption
WithDividePubKey set asymmetrical public key for each signning/verify
func WithDivideSecret ¶
func WithDivideSecret(secret []byte) DivideOption
WithDivideSecret set symmetric key for each signning/verify
type JWT ¶
type JWT interface { Sign(claims jwt.Claims, opts ...DivideOption) (string, error) SignByHS256(claims jwt.Claims, opts ...DivideOption) (string, error) SignByES256(claims jwt.Claims, opts ...DivideOption) (string, error) ParseClaims(token string, claimsPtr jwt.Claims, opts ...DivideOption) error ParseClaimsByHS256(token string, claimsPtr jwt.Claims, opts ...DivideOption) error ParseClaimsByES256(token string, claimsPtr jwt.Claims, opts ...DivideOption) error ParseClaimsByRS256(token string, claimsPtr jwt.Claims, opts ...DivideOption) error }
JWT jwt tool to sign & parse(with/without verify) token
Example ¶
secret = []byte("4738947328rh3ru23f32hf238f238fh28f") j, err := New( WithSignMethod(SignMethodHS256), WithSecretByte(secret), ) if err != nil { log.Shared.Panic("new jwt", zap.Error(err)) } type jwtClaims struct { jwt.RegisteredClaims } claims := &jwtClaims{ jwt.RegisteredClaims{ Subject: "laisky", }, } // signing token, err := j.Sign(claims) if err != nil { log.Shared.Panic("sign jwt", zap.Error(err)) } // verify claims = &jwtClaims{} if err := j.ParseClaims(token, claims); err != nil { log.Shared.Panic("sign jwt", zap.Error(err)) }
Output:
type Option ¶
type Option func(*jwtType) error
Option options to setup JWT
func WithPriKeyByte ¶
WithPriKeyByte set jwt asymmetrical private key
func WithPubKeyByte ¶
WithPubKeyByte set jwt asymmetrical public key
func WithSecretByte ¶
WithSecretByte set jwt symmetric signning key
func WithSignMethod ¶
func WithSignMethod(method jwt.SigningMethod) Option
WithSignMethod set jwt signing method
Click to show internal directories.
Click to hide internal directories.