Documentation ¶
Index ¶
- Variables
- func GetClaimsInt64Ptr(claims jwt.MapClaims, key string) *int64
- func GetClaimsIssuerAndExpiresAt(claims jwt.Claims) (issuer *string, expiresAt *jwt.NumericDate)
- func GetClaimsIssuerAndExpiresAt2(claims jwt.MapClaims) (issuer *string, expiresAt *jwt.NumericDate)
- func GetClaimsString(claims jwt.MapClaims, key string) string
- func GetClaimsStringPtr(claims jwt.MapClaims, key string) *string
- func ParseJwtToken(jwtToken *string, secret string) (jwt.Claims, error)
- type BaseClaims
- type CustomClaims
- type JWTConfig
- type JwtUtil
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrTokenExpired = errors.New("token is expired") ErrTokenNotValidYet = errors.New("token not active yet") ErrTokenMalformed = errors.New("that's not even a token") ErrTokenInvalid = errors.New("couldn't handle this token") )
View Source
var (
Concurrency_Control = &singleflight.Group{}
)
Functions ¶
func GetClaimsInt64Ptr ¶
func GetClaimsIssuerAndExpiresAt ¶
func GetClaimsIssuerAndExpiresAt(claims jwt.Claims) (issuer *string, expiresAt *jwt.NumericDate)
func GetClaimsIssuerAndExpiresAt2 ¶
func GetClaimsIssuerAndExpiresAt2(claims jwt.MapClaims) (issuer *string, expiresAt *jwt.NumericDate)
func GetClaimsString ¶
func GetClaimsStringPtr ¶
func ParseJwtToken ¶
Types ¶
type BaseClaims ¶
type BaseClaims struct { UserId string `json:"user_id"` // Username string `json:"username"` // Roles string `json:"roles,omitempty"` // Groups string `json:"groups,omitempty"` // TenantId string `json:"tenant_id,omitempty"` // our's From uint8 `json:"from,omitempty"` // login from UserIdInIdp string `json:"user_id_in_idp,omitempty"` // authing use sub as user id, Idp string `json:"idp,omitempty"` // Unionid string `json:"unionid,omitempty"` // only used for parsing third jwt string }
if put user info to redis/cache, then we can use less props, more props can get from cache/db if didn't use cache, then we can add more props here more props means the jwt string will become large
type CustomClaims ¶
type CustomClaims struct { jwt.RegisteredClaims BaseClaims BufferTime int64 `json:"buffer_time,omitempty"` // }
Custom claims structure
func ParseJwtTokenWithClaims ¶
func ParseJwtTokenWithClaims(jwtToken *string, secret string) (*CustomClaims, error)
self jwt token, no need to check activated
type JWTConfig ¶
type JWTConfig struct { SigningKey string `yaml:"signingKey" json:"signing-key"` // jwt签名 ExpiresTime string `yaml:"expiresTime" json:"expires-time"` // 过期时间 BufferTime string `yaml:"bufferTime" json:"buffer-time"` // 缓冲时间 Issuer string `yaml:"issuer" json:"issuer"` // 签发者, domain format }
func (*JWTConfig) GetBufferTime ¶
func (*JWTConfig) GetExpiresTime ¶
type JwtUtil ¶
type JwtUtil interface { CreateClaims(baseClaims *BaseClaims) *CustomClaims CreateToken(claims *CustomClaims) (string, error) // check the claims first and create token CreateTokenRaw(claims *CustomClaims) (string, error) // create token with provide claims, did not check the claims CreateTokenByOldToken(oldToken string, claims *CustomClaims) (string, error) ParseToken(jwtToken string) (*CustomClaims, error) // contains filtered or unexported methods }
Click to show internal directories.
Click to hide internal directories.