mirror of
https://github.com/weloe/token-go.git
synced 2025-10-03 14:46:29 +08:00
refactor: add LogoutByToken() and SetJwtSecretKey()
This commit is contained in:
@@ -49,6 +49,10 @@ type TokenConfig struct {
|
||||
CookieConfig *CookieConfig
|
||||
}
|
||||
|
||||
func (t *TokenConfig) SetJwtSecretKey(secretKey string) {
|
||||
t.JwtSecretKey = secretKey
|
||||
}
|
||||
|
||||
func DefaultTokenConfig() *TokenConfig {
|
||||
return &TokenConfig{
|
||||
TokenStyle: "uuid",
|
||||
|
@@ -301,7 +301,7 @@ func (e *Enforcer) Logout(ctx ctx.Context) error {
|
||||
tokenConfig.CookieConfig.Domain)
|
||||
}
|
||||
|
||||
err := e.logoutByToken(token)
|
||||
err := e.LogoutByToken(token)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
@@ -14,6 +14,7 @@ type IEnforcer interface {
|
||||
Login(id string, ctx ctx.Context) (string, error)
|
||||
LoginByModel(id string, loginModel *model.Login, ctx ctx.Context) (string, error)
|
||||
Logout(ctx ctx.Context) error
|
||||
LogoutByToken(token string) error
|
||||
IsLogin(ctx ctx.Context) (bool, error)
|
||||
IsLoginById(id string) (bool, error)
|
||||
GetLoginId(ctx ctx.Context) (string, error)
|
||||
|
@@ -76,8 +76,8 @@ func (e *Enforcer) ResponseToken(tokenValue string, loginModel *model.Login, ctx
|
||||
return nil
|
||||
}
|
||||
|
||||
// logoutByToken clear token info
|
||||
func (e *Enforcer) logoutByToken(token string) error {
|
||||
// LogoutByToken clear token info
|
||||
func (e *Enforcer) LogoutByToken(token string) error {
|
||||
var err error
|
||||
// delete token-id
|
||||
id := e.GetIdByToken(token)
|
||||
@@ -143,3 +143,7 @@ func (e *Enforcer) spliceSessionKey(id string) string {
|
||||
func (e *Enforcer) spliceTokenKey(id string) string {
|
||||
return e.config.TokenName + ":" + e.loginType + ":token:" + id
|
||||
}
|
||||
|
||||
func (e *Enforcer) SetJwtSecretKey(key string) {
|
||||
e.config.JwtSecretKey = key
|
||||
}
|
||||
|
Reference in New Issue
Block a user