Documentation ¶
Index ¶
- Variables
- func CreateClaims(issuer string, inr time.Duration) jwt.Claims
- func HMACVerifyCustomJWT(tokenString string, opt HMACVerifyOption, claims Claims) (bool, error)
- func LoadRSAPrivateKey(key []byte) (*rsa.PrivateKey, error)
- func LoadRSAPrivateKeyFromPEM(keyFile, passFile string) (*rsa.PrivateKey, error)
- func LoadRSAPublicKey(key []byte) (*rsa.PublicKey, error)
- func LoadRSAPublicKeyFromPEM(file string) (*rsa.PublicKey, error)
- func RS256SignJWT(claims jwt.Claims, key *rsa.PrivateKey) (string, error)
- func RS512SignJWT(claims jwt.Claims, key *rsa.PrivateKey) (string, error)
- func RSAVerifyCustomJWT(tokenString string, opt VerifyOption, claims Claims) (bool, error)
- func RSAVerifyJWT(tokenString string, opt VerifyOption) (bool, *jwt.StandardClaims, error)
- func RSAVerifyJWTWithKid(tokenString string, opt KidVerifyOption) (bool, *jwt.StandardClaims, error)
- type Claims
- type GetPublicKeyByKidFunc
- type GetPublicKeyFunc
- type HMACVerifyOption
- type KidVerifyOption
- type StandardClaims
- type VerifyOption
Constants ¶
This section is empty.
Variables ¶
var ( ErrParseClaimsFailed = errors.New("failed to parse not standard claims") ErrNoPublicKey = errors.New("no public key to verity JWT") ErrEmptyToken = errors.New("token is empty") )
var (
ErrInvalidPrivateKeyFile = errors.New("invalid private key file")
)
Functions ¶
func CreateClaims ¶
CreateClaims 根据 issuer 与过期时间间隔创建一个 JWT Claims. 例如,issuer 可以是一个 APP ID.
func HMACVerifyCustomJWT ¶
func HMACVerifyCustomJWT(tokenString string, opt HMACVerifyOption, claims Claims) (bool, error)
func LoadRSAPrivateKey ¶
func LoadRSAPrivateKey(key []byte) (*rsa.PrivateKey, error)
LoadRSAPrivateKey 从私钥的字节序列中加载 RSA 私钥
func LoadRSAPrivateKeyFromPEM ¶
func LoadRSAPrivateKeyFromPEM(keyFile, passFile string) (*rsa.PrivateKey, error)
LoadRSAPrivateKeyFromPEM 从 PEM 私钥文件 keyFile 与密码文件 passFile 中加载 RSA 私钥
func LoadRSAPublicKey ¶
LoadRSAPublicKey 从字节序列中加载 RSA 公钥
func LoadRSAPublicKeyFromPEM ¶
LoadRSAPublicKeyFromPEM 从 PEM 公钥文件 file 中加载 RSA 公钥
func RS256SignJWT ¶
func RS256SignJWT(claims jwt.Claims, key *rsa.PrivateKey) (string, error)
RS256SignJWT 使用 RS256 算法对 claims 进行签名
func RS512SignJWT ¶
func RS512SignJWT(claims jwt.Claims, key *rsa.PrivateKey) (string, error)
RS512SignJWT 使用 RS512 算法对 claims 进行签名
func RSAVerifyCustomJWT ¶
func RSAVerifyCustomJWT(tokenString string, opt VerifyOption, claims Claims) (bool, error)
RSAVerifyCustomJWT 使用 RSA 算法 (RS256/RS384/RS512) 对包含自定义 Claims 的 JWT Token 进行验证。
func RSAVerifyJWT ¶
func RSAVerifyJWT(tokenString string, opt VerifyOption) (bool, *jwt.StandardClaims, error)
RSAVerifyJWT 使用 RSA 算法 (RS256/RS384/RS512) 对 JWT Token 进行验证。
func RSAVerifyJWTWithKid ¶
func RSAVerifyJWTWithKid(tokenString string, opt KidVerifyOption) (bool, *jwt.StandardClaims, error)
RSAVerifyJWTWithKid 使用 RSA 算法 (RS256/RS384/RS512) 对 JWT Token 进行验证。
Types ¶
type GetPublicKeyByKidFunc ¶
GetPublicKeyByKidFunc 根据 kid 获取一个 rsa.PublicKey
type GetPublicKeyFunc ¶
GetPublicKeyFunc 根据 iss 获取一个 rsa.PublicKey
type HMACVerifyOption ¶
type HMACVerifyOption struct { MaxExpInterval time.Duration // 最大过期时间间隔,单位为秒 // app-key与密钥的对应关系 // key: app-key // value: 密钥的 byte 数组 SecretKeys map[string][]byte }
HMACVerifyOption 验证参数
type KidVerifyOption ¶
type KidVerifyOption struct { MaxExpInterval time.Duration // 最大过期时间间隔,单位为秒 GetPublicKeyFunc GetPublicKeyByKidFunc // PublicKey 查找函数 }
KidVerifyOption 验证参数
type StandardClaims ¶
type StandardClaims struct {
jwt.StandardClaims
}
StandardClaims is a wrapper for jwt.StandardClaims
func (*StandardClaims) GetExpiresAt ¶
func (c *StandardClaims) GetExpiresAt() int64
func (*StandardClaims) GetIssuedAt ¶
func (c *StandardClaims) GetIssuedAt() int64
func (*StandardClaims) GetIssuer ¶
func (c *StandardClaims) GetIssuer() string
type VerifyOption ¶
type VerifyOption struct { MaxExpInterval time.Duration // 最大过期时间间隔,单位为秒 GetPublicKeyFunc GetPublicKeyFunc // PublicKey 查找函数 }
VerifyOption 验证参数