feature:提取创建claims和token的方法,方便后续插件扩展。
This commit is contained in:
@@ -2,6 +2,7 @@ package utils
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
|
||||
systemReq "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gofrs/uuid/v5"
|
||||
@@ -123,3 +124,19 @@ func GetUserName(c *gin.Context) string {
|
||||
return waitUse.Username
|
||||
}
|
||||
}
|
||||
|
||||
func LoginToken(user system.Login) (token string, claims systemReq.CustomClaims, err error) {
|
||||
j := &JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名
|
||||
claims = j.CreateClaims(systemReq.BaseClaims{
|
||||
UUID: user.GetUUID(),
|
||||
ID: user.GetUserId(),
|
||||
NickName: user.GetNickname(),
|
||||
Username: user.GetUsername(),
|
||||
AuthorityId: user.GetAuthorityId(),
|
||||
})
|
||||
token, err = j.CreateToken(claims)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user