28 lines
678 B
Go
28 lines
678 B
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
|
|
"36wisdom/biz/consts"
|
|
"36wisdom/common/auth"
|
|
)
|
|
|
|
// authSvc 鉴权服务:token 签发与解析,密钥统一来自配置 auth.secret。
|
|
type authSvc struct{}
|
|
|
|
var Auth = &authSvc{}
|
|
|
|
func (s *authSvc) GenerateToken(ctx context.Context, uid int64, role string) (string, error) {
|
|
return auth.GenerateToken(secret(ctx), uid, role, consts.AuthExpireSeconds)
|
|
}
|
|
|
|
func (s *authSvc) ParseToken(ctx context.Context, tokenString string) (int64, string, error) {
|
|
return auth.ParseToken(secret(ctx), tokenString)
|
|
}
|
|
|
|
func secret(ctx context.Context) string {
|
|
return g.Cfg().MustGet(ctx, "auth.secret").String()
|
|
}
|