Feat: 登录接口实现
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-04-09 11:48:44 +08:00
parent 0df2aaa82f
commit 35801f5ee9
13 changed files with 160 additions and 39 deletions

View File

@@ -23,7 +23,7 @@ func VerifyToken(authorization string) error {
return err
}
func NewToken(auds ...string) (string, error) {
func NewToken(expire time.Duration, auds ...string) (string, error) {
if len(auds) == 0 {
auds = []string{"non-audience"}
}
@@ -32,7 +32,7 @@ func NewToken(auds ...string) (string, error) {
"bar",
jwt.RegisteredClaims{
// A usual scenario is to set the expiration time relative to the current time
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Duration(config.Cfg.Security.Jwt.Expire) * time.Second)),
ExpiresAt: jwt.NewNumericDate(time.Now().Add(expire)),
IssuedAt: jwt.NewNumericDate(time.Now()),
NotBefore: jwt.NewNumericDate(time.Now()),
Issuer: "drivelinked",
@@ -48,3 +48,11 @@ func NewToken(auds ...string) (string, error) {
}
return ss, nil
}
func NewShortToken(auds ...string) (string, error) {
return NewToken(time.Duration(config.Cfg.Security.Jwt.Expire) * time.Second)
}
func NewRefreshToken(auds ...string) (string, error) {
return NewToken(24 * time.Hour)
}