xjwt

package
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

jwt

配置文件增加

JWT_SIGNING_KEY = 签名秘钥 # 默认 gwt_sign_key 类型:string
JWT_SIGNING_METHOD = 加密方式[HS256, HS384, HS512] # 默认 HS256 类型:string
JWT_EXPIRES_TIME = 有效时间 # 默认 10  单位:分钟 类型:int

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SignKey     string = "gwt_sign_key"
	ExpiresTime int    = 259200
)

一些常量

Functions

func GetExpiresTime

func GetExpiresTime() int64

GetExpiresTime 获取过期时间

func GetSigningKey

func GetSigningKey() []byte

GetSigningKey 获取signingKey

func GetSigningMethod

func GetSigningMethod() (method jwt.SigningMethod)

GetSigningMethod 获取签名方法

func ParsePKCS8PrivateKeyJwt

func ParsePKCS8PrivateKeyJwt(privateKey string, issuer string, expiresAt time.Time) (tokenStr string, err error)
对应java版本
PrivateKey priKey = KeyFactory.
	getInstance("RSA").
	generatePrivate(
		new PKCS8EncodedKeySpec(
			(new BASE64Decoder()).decodeBuffer(privateKey)
		)
	);
Algorithm algorithm = Algorithm.RSA256((RSAPublicKey)null, (RSAPrivateKey)priKey);
return JWT.create().withIssuer(issuer).withExpiresAt(expireAt).withPayload(payload).sign(algorithm);

ParsePKCS8PrivateKeyJwt 根据pkcs8 私钥生成对应jwt token @param privateKey 私钥 @param payload 负载,可为空 @param issuer jwt颁发者标识 @param expireAt jwt过期时间

Types

type CustomClaims

type CustomClaims struct {
	Data json.RawMessage
	jwt.StandardClaims
}

CustomClaims Structured version of Claims Section, as referenced at https://tools.ietf.org/html/rfc7519#section-4.1 See examples for how to use this with your own claim types

func (CustomClaims) CreateToken

func (claims CustomClaims) CreateToken(ctx context.Context) (string, error)

CreateToken 生成一个token

func (CustomClaims) ParseToken

func (CustomClaims) ParseToken(ctx context.Context, tokenString string) (*CustomClaims, error)

ParseToken 解析Token

func (*CustomClaims) RefreshToken

func (claims *CustomClaims) RefreshToken(ctx context.Context, tokenString string) (string, error)

RefreshToken 更新token

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL