jwt

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sign

func Sign(claim jwtLib.Claims, conf Conf) (string, error)

Sign 签名

func SignWithMap

func SignWithMap(claims MapClaims, conf Conf) (string, error)

SignWithMap 签名

Types

type AppClaims

type AppClaims struct {
	Scopes   []string
	ScopeIDs []int64
	Name     string
	Email    string
	//more...
	jwtLib.StandardClaims
}

AppClaims App票据声明

func Verify

func Verify(tokenString string, conf Conf) (AppClaims, error)

Verify 验证

func (*AppClaims) GetToken

func (c *AppClaims) GetToken(method SigningMethod, secret interface{}) (string, error)

GetToken 获取token

type Conf

type Conf struct {
	PublicKey   string `yaml:"public_key" toml:"public_key" json:"public_key"`       //公钥字符串或公钥文件地址
	PrivateKey  string `yaml:"private_key" toml:"private_key" json:"private_key"`    //私钥字符串或私钥文件地址
	Algorithm   string `yaml:"algorithm" toml:"algorithm" json:"algorithm"`          //加密算法: RS256 | RS512 | HS512
	HmacSecret  string `yaml:"hmac_secret" toml:"hmac_secret" json:"hmac_secret"`    //密钥
	TokenIssuer string `yaml:"token_issuer" toml:"token_issuer" json:"token_issuer"` //令牌颁发者
	// contains filtered or unexported fields
}

Conf 配置信息

<yaml example>

jwt:

public_key:
private_key:
algorithm: RS256
hmac_secret: example
token_issuer: authority

<toml example>

::jwt密钥配置::

jwt

公钥文件或字符串

public_key = ""

私钥文件或字符串

private_key = ""

加密算法: RS256 | RS512 | HS512

algorithm = "RS256"

密钥,当algorithm = "HS512"时需要配置此项

hmac_secret = "example"

令牌颁发者

token_issuer = "authority"

func (*Conf) GetPrivateKeyObj

func (c *Conf) GetPrivateKeyObj() *rsa.PrivateKey

GetPrivateKeyObj 获取私钥对象

func (*Conf) GetPublicKeyObj

func (c *Conf) GetPublicKeyObj() *rsa.PublicKey

GetPublicKeyObj 获取公钥对象

func (*Conf) Load

func (c *Conf) Load()

Load 载入配置

type MapClaims

type MapClaims map[string]interface{}

func VerifyFromMap

func VerifyFromMap(tokenString string, conf Conf) (MapClaims, error)

VerifyFromMap 验证

func (*MapClaims) GetToken

func (c *MapClaims) GetToken(method SigningMethod, secret interface{}) (string, error)

GetToken 获取token

func (MapClaims) Valid

func (c MapClaims) Valid() error

type SigningMethod

type SigningMethod string

SigningMethod 签名方法

const (
	SigningMethodRS256 SigningMethod = "RS256" //SigningMethodRS256 rsa256方法
	SigningMethodRS512 SigningMethod = "RS512" //SigningMethodRS512 rsa512方法
	SigningMethodHS512 SigningMethod = "HS512" //SigningMethodHS512 hmac方法
)

Jump to

Keyboard shortcuts

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