feat: support add token generate function

This commit is contained in:
weloe
2023-05-12 22:16:20 +08:00
parent a89c28076a
commit 164c80ba7a
3 changed files with 8 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
package constant package constant
// tokenStyle constant
const ( const (
UUID = "uuid" UUID = "uuid"
SimpleUUID = "uuid-simple" SimpleUUID = "uuid-simple"

View File

@@ -445,6 +445,12 @@ func (e *Enforcer) GetRequestToken(ctx ctx.Context) string {
return tokenValue return tokenValue
} }
// AddTokenGenerateFun add token generate strategy
func (e *Enforcer) AddTokenGenerateFun(tokenStyle string, f model.GenerateFunc) error {
e.generateFunc.AddFunc(tokenStyle, f)
return nil
}
func (e *Enforcer) GetSession(id string) *model.Session { func (e *Enforcer) GetSession(id string) *model.Session {
if v := e.adapter.Get(e.spliceSessionKey(id)); v != nil { if v := e.adapter.Get(e.spliceSessionKey(id)); v != nil {
session := v.(*model.Session) session := v.(*model.Session)

View File

@@ -23,6 +23,7 @@ type IEnforcer interface {
Kickout(id string, device string) error Kickout(id string, device string) error
GetRequestToken(ctx ctx.Context) string GetRequestToken(ctx ctx.Context) string
AddTokenGenerateFun(tokenStyle string, f model.GenerateFunc) error
CheckLogin(ctx ctx.Context) error CheckLogin(ctx ctx.Context) error