jwt

package
v0.0.0-...-08bb878 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBearerToken

func GetBearerToken(ctx context.Context) (string, error)

GetBearerToken 获取用户令牌

func GetCookieToken

func GetCookieToken(ctx context.Context) (string, error)

GetCookieToken 获取用户令牌

func GetFormToken

func GetFormToken(ctx context.Context) (string, error)

GetFormToken 获取用户令牌

func KeyFuncCallback

func KeyFuncCallback(c context.Context, token *jwt.Token, method jwt.SigningMethod, secret interface{}) (interface{}, error)

KeyFuncCallback 解析方法使用此回调函数来提供验证密钥。 该函数接收解析后的内容,但未验证的令牌。这使您可以在令牌的标头(例如 kid),以标识要使用的密钥。

func NewRefreshToken

func NewRefreshToken(_ati string) string

NewRefreshToken new refresh token

func NewTokenID

func NewTokenID(_ati string) string

NewTokenID new ID

func NewWithClaims

func NewWithClaims(c context.Context, claims *UserClaims, method jwt.SigningMethod, secret interface{}) (string, error)

NewWithClaims new claims jwt.NewWithClaims

Types

type Auther

type Auther struct {
	// contains filtered or unexported fields
}

Auther jwt认证

func New

func New(store res.Storer, opts ...Option) *Auther

New 创建认证实例

func (*Auther) DestroyToken

func (a *Auther) DestroyToken(c context.Context, user auth.UserInfo) error

DestroyToken 销毁令牌

func (*Auther) GenerateToken

func (a *Auther) GenerateToken(c context.Context, user auth.UserInfo) (auth.TokenInfo, auth.UserInfo, error)

GenerateToken 生成令牌

func (*Auther) GetUserInfo

func (a *Auther) GetUserInfo(c context.Context, tkn string) (auth.UserInfo, error)

GetUserInfo 获取用户

func (*Auther) RefreshToken

func (a *Auther) RefreshToken(c context.Context, tkn string, chk func(auth.UserInfo, int) error) (auth.TokenInfo, auth.UserInfo, error)

RefreshToken 刷新令牌

func (*Auther) Release

func (a *Auther) Release() error

Release 释放资源

func (*Auther) UpdateAuther

func (a *Auther) UpdateAuther(c context.Context) error

UpdateAuther 更新

type Option

type Option func(*options)

Option 定义参数项

func SetExpired

func SetExpired(expired int) Option

SetExpired 设定令牌过期时长(单位秒,默认2小时)

func SetFixClaimsFunc

func SetFixClaimsFunc(f func(context.Context, *UserClaims) (int, error)) Option

SetFixClaimsFunc 设定修复载体的方法

func SetKeyFunc

func SetKeyFunc(f func(context.Context, *jwt.Token, jwt.SigningMethod, interface{}) (interface{}, error)) Option

SetKeyFunc 设定签名key

func SetNewClaims

func SetNewClaims(f func(context.Context, *UserClaims, jwt.SigningMethod, interface{}) (string, error)) Option

SetNewClaims 设定声明内容

func SetParseClaimsFunc

func SetParseClaimsFunc(f func(context.Context, string) (*UserClaims, error)) Option

SetParseClaimsFunc 设定解析令牌方法

func SetParseRefreshFunc

func SetParseRefreshFunc(f func(context.Context, string) (*UserClaims, error)) Option

SetParseRefreshFunc 设定解析刷新令牌方法

func SetRefresh

func SetRefresh(refresh int) Option

SetRefresh 设定令牌过期时长(单位秒,默认7天)

func SetSigningMethod

func SetSigningMethod(method jwt.SigningMethod) Option

SetSigningMethod 设定签名方式

func SetSigningSecret

func SetSigningSecret(secret string) Option

SetSigningSecret 设定签名方式

func SetTokenFunc

func SetTokenFunc(f func(context.Context) (string, error)) Option

SetTokenFunc 设定令牌Token

func SetUpdateFunc

func SetUpdateFunc(f func(context.Context) error) Option

SetUpdateFunc 设定刷新者

type TokenInfo

type TokenInfo struct {
	// TokenType    string `json:"token_type,omitempty"`    // 令牌类型
	TokenID      string `json:"token_id,omitempty"`
	AccessToken  string `json:"access_token,omitempty"`    // 访问令牌
	ExpiresAt    int64  `json:"expires_at,omitempty"`      // 访问令牌过期时间
	RefreshToken string `json:"refresh_token,omitempty"`   // 刷新令牌
	RefreshExpAt int64  `json:"refresh_expires,omitempty"` // 刷新令牌过期时间
}

TokenInfo 令牌信息

func (*TokenInfo) EncodeToJSON

func (t *TokenInfo) EncodeToJSON() ([]byte, error)

EncodeToJSON to json

func (*TokenInfo) GetAccessToken

func (t *TokenInfo) GetAccessToken() string

GetAccessToken access token

func (*TokenInfo) GetExpiresAt

func (t *TokenInfo) GetExpiresAt() int64

GetExpiresAt expires at

func (*TokenInfo) GetRefreshExpAt

func (t *TokenInfo) GetRefreshExpAt() int64

GetRefreshExpAt refresh expires

func (*TokenInfo) GetRefreshToken

func (t *TokenInfo) GetRefreshToken() string

GetRefreshToken refresh token

func (*TokenInfo) GetTokenID

func (t *TokenInfo) GetTokenID() string

GetTokenID token id

type UserClaims

type UserClaims struct {
	jwt.StandardClaims

	// TokenID -> Id
	// UserID -> Subject -> sub, GetOrgCode为空,提供用户平台ID, 否则提供用户租户ID
	Account   string   `json:"ati,omitempty"` // 登陆ID, 本身不具备任何意义,只是标记登陆方式, 使用token反向加密
	TokenPID  string   `json:"pti,omitempty"` // 子母令牌
	Account1  string   `json:"at1,omitempty"` // 用户登录信息
	Account2  string   `json:"at2,omitempty"` // 用户自定义信息
	UserName  string   `json:"nam,omitempty"` // 用户名
	UserRoles []string `json:"ros,omitempty"` // 角色ID, 该角色是平台角色, 也可以理解为平台给机构的角色
	OrgCode   string   `json:"ogc,omitempty"` // 组织/租户code
	OrgAdmin  string   `json:"oga,omitempty"` // admin'为用户管理员, GetOrgCode为空,提供
	OrgUsrID  string   `json:"ogu,omitempty"` // 用户自定义ID
	Agent     string   `json:"agt,omitempty"` // 登录使用的第三方应用
	Scope     string   `json:"sce,omitempty"` // 权限作用域
	Domain    string   `json:"dom,omitempty"` // 业务域,主要用户当前用户跨应用的业务关联,暂时不使用

}

UserClaims 用户信息声明

func NewUserInfo

func NewUserInfo(user auth.UserInfo) *UserClaims

NewUserInfo 获取用户信息

func (*UserClaims) GetAccount

func (u *UserClaims) GetAccount() string

GetAccount xxx

func (*UserClaims) GetAccount1

func (u *UserClaims) GetAccount1() string

GetAccount1 xxx

func (*UserClaims) GetAccount2

func (u *UserClaims) GetAccount2() string

GetAccount2 xxx

func (*UserClaims) GetAgent

func (u *UserClaims) GetAgent() string

GetAgent xxx

func (*UserClaims) GetAudience

func (u *UserClaims) GetAudience() string

GetAudience xxx

func (*UserClaims) GetDomain

func (u *UserClaims) GetDomain() string

GetDomain xxx

func (*UserClaims) GetIssuer

func (u *UserClaims) GetIssuer() string

GetIssuer xxx

func (*UserClaims) GetOrgAdmin

func (u *UserClaims) GetOrgAdmin() string

GetOrgAdmin xxx

func (*UserClaims) GetOrgCode

func (u *UserClaims) GetOrgCode() string

GetOrgCode xxx

func (*UserClaims) GetOrgUsrID

func (u *UserClaims) GetOrgUsrID() string

GetOrgUsrID xxx

func (*UserClaims) GetScope

func (u *UserClaims) GetScope() string

GetScope xxx

func (*UserClaims) GetTokenID

func (u *UserClaims) GetTokenID() string

GetTokenID xxx

func (*UserClaims) GetTokenPID

func (u *UserClaims) GetTokenPID() string

GetTokenPID xxx

func (*UserClaims) GetUserID

func (u *UserClaims) GetUserID() string

GetUserID xxx

func (*UserClaims) GetUserName

func (u *UserClaims) GetUserName() string

GetUserName xxx

func (*UserClaims) GetUserRoles

func (u *UserClaims) GetUserRoles() []string

GetUserRoles xxx

func (*UserClaims) GetUserSvcRoles

func (u *UserClaims) GetUserSvcRoles(svc string) []string

GetUserSvcRoles xxx

Jump to

Keyboard shortcuts

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