Documentation
¶
Index ¶
- func ExtractJWTFromRequest(r *http.Request) (string, error)
- func GenerateGenericJWT[T any](payload T, secretKey []byte, signingMethod jwt.SigningMethod) (string, error)
- func GenerateJWT(mapClaims jwt.MapClaims, secretKey []byte, signingMethod jwt.SigningMethod) (string, error)
- func GenerateJWTWithHeader(payload jwt.MapClaims, secretKey []byte, signingMethod jwt.SigningMethod, ...) (string, error)
- func GenerateShortLivedJWT(payload jwt.MapClaims, secretKey []byte, signingMethod jwt.SigningMethod, ...) (string, error)
- func GetJWTClaims(tokenString string) (map[string]interface{}, error)
- func GetJWTHeader(tokenString string) (map[string]interface{}, error)
- func GetJWTIssuedAt(tokenString string) (*time.Time, error)
- func IsJWTExpired(tokenString string) (bool, error)
- func NewJWTId() string
- func NewRefreshToken() (string, error)
- func ParseJWTClaimsToStruct[T any](tokenString string) (*T, error)
- func ParseJWTPayload(tokenString string) (jwt.MapClaims, error)
- func RefreshJWT(tokenString string, secretKey []byte, newExpiration time.Time) (string, error)
- func ToMapClaims[T any](payload T) (jwt.MapClaims, error)
- func ValidateJWTAlgorithm(tokenString string, expectedAlgorithm string) (bool, error)
- func ValidateJWTAudience(tokenString string, expectedAudience string) (bool, error)
- func ValidateJWTIssuer(tokenString string, expectedIssuer string) (bool, error)
- func VerifyJWT(tokenString string, secretKey []byte) (jwt.MapClaims, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractJWTFromRequest ¶
ExtractJWTFromRequest 从请求中提取JWT
func GenerateGenericJWT ¶
func GenerateGenericJWT[T any](payload T, secretKey []byte, signingMethod jwt.SigningMethod) (string, error)
GenerateGenericJWT 生成 JWT
func GenerateJWT ¶
func GenerateJWT(mapClaims jwt.MapClaims, secretKey []byte, signingMethod jwt.SigningMethod) (string, error)
GenerateJWT 生成 JWT
func GenerateJWTWithHeader ¶
func GenerateJWTWithHeader(payload jwt.MapClaims, secretKey []byte, signingMethod jwt.SigningMethod, customHeader map[string]interface{}) (string, error)
GenerateJWTWithHeader 生成带自定义头部的JWT
func GenerateShortLivedJWT ¶
func GenerateShortLivedJWT(payload jwt.MapClaims, secretKey []byte, signingMethod jwt.SigningMethod, duration time.Duration) (string, error)
GenerateShortLivedJWT 生成短期有效的JWT
func GetJWTClaims ¶
func GetJWTHeader ¶
GetJWTHeader 获取JWT头部
func GetJWTIssuedAt ¶
GetJWTIssuedAt 获取JWT签发时间
func ParseJWTClaimsToStruct ¶
ParseJWTClaimsToStruct 解析 JWT 的负载部分,不验证签名,仅解析。
func ParseJWTPayload ¶
ParseJWTPayload 使用 github.com/golang-jwt/jwt/v5 从 JWT 中解析出 payload
func RefreshJWT ¶
RefreshJWT 刷新JWT
func ToMapClaims ¶
ToMapClaims 将泛型 payload 转换为 jwt.MapClaims
func ValidateJWTAlgorithm ¶
ValidateJWTAlgorithm 验证JWT算法
func ValidateJWTAudience ¶
ValidateJWTAudience 验证JWT受众
func ValidateJWTIssuer ¶
ValidateJWTIssuer 验证JWT发行者
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.