token

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ACCESS              = "access:"
	AUTH_TO_ACCESS      = "auth_to_access:"
	AUTH                = "auth:"
	REFRESH_AUTH        = "refresh_auth:"
	ACCESS_TO_REFRESH   = "access_to_refresh:"
	REFRESH             = "refresh:"
	REFRESH_TO_ACCESS   = "refresh_to_access:"
	CLIENT_ID_TO_ACCESS = "client_id_to_access:"
	UNAME_TO_ACCESS     = "uname_to_access:"
)

Variables

This section is empty.

Functions

func AccessGenerate

func AccessGenerate() oauth2.AccessGenerate

func DelTokenCacheFromRedis

func DelTokenCacheFromRedis(userId int64)

DelTokenCacheFromRedis 用户密码修改后,删除redis所有的token

func Init

func Init()

func InitTokenGenerator

func InitTokenGenerator() oauth2.AccessGenerate

func InitTokenStore

func InitTokenStore() oauth2.TokenStore

func NewDatabaseTokenStore

func NewDatabaseTokenStore() (oauth2.TokenStore, error)

func NewFileTokenStore

func NewFileTokenStore(filename string) (oauth2.TokenStore, error)

func NewJWTAccessGenerate

func NewJWTAccessGenerate() oauth2.AccessGenerate

func NewMemeoryTokenStore

func NewMemeoryTokenStore() (oauth2.TokenStore, error)

func NewRedisTokenStore

func NewRedisTokenStore() (oauth2.TokenStore, error)

func NewUUIDAccessGenerate

func NewUUIDAccessGenerate() oauth2.AccessGenerate

*

  • UUID Token Generator

func ParseToken

func ParseToken(tokenString string) (oauth2.TokenInfo, error)

func TokenStore

func TokenStore() oauth2.TokenStore

func ValidTokenCacheToRedis

func ValidTokenCacheToRedis(userId int64)

本文件专门处理 token 缓存到 redis 的相关逻辑

Types

type Authentication

type Authentication struct {
	UserId        string       `json:"user_id"`
	Request       TokenRequest `json:"request"`
	Authenticated bool         `json:"authenticated"`
}

func ParseAuthentication

func ParseAuthentication(authenticationString string) (*Authentication, error)

func (*Authentication) GetId

func (a *Authentication) GetId() string

type DatabaseTokenStore

type DatabaseTokenStore struct {
}

func (*DatabaseTokenStore) Create

func (s *DatabaseTokenStore) Create(ctx context.Context, info oauth2.TokenInfo) error

create and store the new token information

func (*DatabaseTokenStore) GetByAccess

func (s *DatabaseTokenStore) GetByAccess(ctx context.Context, access string) (oauth2.TokenInfo, error)

use the access token for token information data

func (*DatabaseTokenStore) GetByCode

func (s *DatabaseTokenStore) GetByCode(ctx context.Context, code string) (oauth2.TokenInfo, error)

use the authorization code for token information data

func (*DatabaseTokenStore) GetByRefresh

func (s *DatabaseTokenStore) GetByRefresh(ctx context.Context, refresh string) (oauth2.TokenInfo, error)

use the refresh token for token information data

func (*DatabaseTokenStore) GetToken

func (s *DatabaseTokenStore) GetToken(ctx context.Context, key string) (oauth2.TokenInfo, error)

func (*DatabaseTokenStore) RemoveByAccess

func (s *DatabaseTokenStore) RemoveByAccess(ctx context.Context, access string) error

use the access token to delete the token information

func (*DatabaseTokenStore) RemoveByCode

func (s *DatabaseTokenStore) RemoveByCode(ctx context.Context, code string) error

delete the authorization code

func (*DatabaseTokenStore) RemoveByRefresh

func (s *DatabaseTokenStore) RemoveByRefresh(ctx context.Context, refresh string) error

use the refresh token to delete the token information

type ITokenResolver

type ITokenResolver interface {
	Resolve(context.Context, string) (oauth2.TokenInfo, error)
}

func InitTokenResolver

func InitTokenResolver() ITokenResolver

func NewJWTTokenResolver

func NewJWTTokenResolver() ITokenResolver

*

  • JWT Token Resolver

func NewStoreTokenResolver

func NewStoreTokenResolver() ITokenResolver

*

  • Store Token Resolver

func TokenResolver

func TokenResolver() ITokenResolver

type ITokenStore

type ITokenStore interface {
	oauth2.TokenStore
	GetToken(context.Context, string) (oauth2.TokenInfo, error)
}

type JWTTokenGenerator

type JWTTokenGenerator struct {
}

*

  • JWT Token Generator

func (*JWTTokenGenerator) Token

func (a *JWTTokenGenerator) Token(ctx context.Context, data *oauth2.GenerateBasic, isGenRefresh bool) (string, string, error)

type JWTTokenResolver

type JWTTokenResolver struct{}

func (*JWTTokenResolver) Resolve

func (v *JWTTokenResolver) Resolve(ctx context.Context, tokenValue string) (oauth2.TokenInfo, error)
type StandardClaims struct {
	Audience  string `json:"aud,omitempty"`
	ExpiresAt int64  `json:"exp,omitempty"`	AccessCreateAt + AccessExpiresIn
	Id        string `json:"jti,omitempty"`
	IssuedAt  int64  `json:"iat,omitempty"` AccessCreateAt
	Issuer    string `json:"iss,omitempty"`
	NotBefore int64  `json:"nbf,omitempty"`
	Subject   string `json:"sub,omitempty"` UserId
}

type OAuth2Token

type OAuth2Token struct {
	models.Token
}

type RedisTokenStore

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

func (*RedisTokenStore) Create

func (s *RedisTokenStore) Create(ctx context.Context, info oauth2.TokenInfo) error

create and store the new token information

func (*RedisTokenStore) GetByAccess

func (s *RedisTokenStore) GetByAccess(ctx context.Context, access string) (oauth2.TokenInfo, error)

use the access token for token information data

func (*RedisTokenStore) GetByCode

func (s *RedisTokenStore) GetByCode(ctx context.Context, code string) (oauth2.TokenInfo, error)

use the authorization code for token information data

func (*RedisTokenStore) GetByRefresh

func (s *RedisTokenStore) GetByRefresh(ctx context.Context, refresh string) (oauth2.TokenInfo, error)

use the refresh token for token information data

func (*RedisTokenStore) GetToken

func (s *RedisTokenStore) GetToken(ctx context.Context, authenticationId string) (oauth2.TokenInfo, error)

func (*RedisTokenStore) RedisKey

func (s *RedisTokenStore) RedisKey(name string, key string) string

func (*RedisTokenStore) RemoveByAccess

func (s *RedisTokenStore) RemoveByAccess(ctx context.Context, access string) error

use the access token to delete the token information

func (*RedisTokenStore) RemoveByCode

func (s *RedisTokenStore) RemoveByCode(ctx context.Context, code string) error

delete the authorization code

func (*RedisTokenStore) RemoveByRefresh

func (s *RedisTokenStore) RemoveByRefresh(ctx context.Context, refresh string) error

use the refresh token to delete the token information

type RedisUserTokenCache

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

保存用户的所有Token

func CreateRedisUserTokenStorage

func CreateRedisUserTokenStorage(userId int64) *RedisUserTokenCache

func (*RedisUserTokenCache) ClearUserTokens

func (u *RedisUserTokenCache) ClearUserTokens() bool

ClearUserToken 清除某个用户的全部缓存,当用户更改密码或者用户被禁用则删除该用户的全部缓存

func (*RedisUserTokenCache) DelOverMaxOnlineCache

func (u *RedisUserTokenCache) DelOverMaxOnlineCache() bool

DelOverMaxOnlineCache 删除缓存,删除超过系统允许最大在线数量之外的用户

func (*RedisUserTokenCache) ReleaseRedisConn

func (u *RedisUserTokenCache) ReleaseRedisConn()

ReleaseRedisConn 释放redis

func (*RedisUserTokenCache) SetToken

func (u *RedisUserTokenCache) SetToken(tokenExpire int64, token string) bool

SetTokenCache 设置缓存

func (*RedisUserTokenCache) SetUserTokensExpire

func (u *RedisUserTokenCache) SetUserTokensExpire(ts int64) bool

SetUserTokenExpire 设置用户的 usertoken 键过期时间 参数: 时间戳

func (*RedisUserTokenCache) UserTokenExists

func (u *RedisUserTokenCache) UserTokenExists(token string) (exists bool)

TokenCacheIsExists 查询token是否在redis存在

type StoreTokenResolver

type StoreTokenResolver struct {
	TokenStore oauth2.TokenStore `inject:"tokenStore"`
}

func (*StoreTokenResolver) Resolve

func (v *StoreTokenResolver) Resolve(ctx context.Context, tokenValue string) (oauth2.TokenInfo, error)

type TokenRequest

type TokenRequest struct {
	ClientId          string            `json:"client_id"`
	Scope             string            `json:"scope"`
	GrantType         string            `json:"grant_type"`
	RequestParameters map[string]string `json:"request_parameters"`
}

type UUIDTokenGenerator

type UUIDTokenGenerator struct {
	TokenStore ITokenStore `inject:"tokenStore"`
}

func (*UUIDTokenGenerator) Token

func (g *UUIDTokenGenerator) Token(ctx context.Context, data *oauth2.GenerateBasic, isGenRefresh bool) (access string, refresh string, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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