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