use time.Duration in token expiry env vars
This commit is contained in:
parent
89609ae5e6
commit
eb928912af
5 changed files with 15 additions and 15 deletions
|
|
@ -130,7 +130,7 @@ func (rs *Resource) token(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
token := &Token{
|
||||
Token: uuid.NewV4().String(),
|
||||
Expiry: time.Now().Add(time.Minute * rs.Token.jwtRefreshExpiry),
|
||||
Expiry: time.Now().Add(rs.Token.jwtRefreshExpiry),
|
||||
UpdatedAt: time.Now(),
|
||||
AccountID: acc.ID,
|
||||
Mobile: ua.Mobile(),
|
||||
|
|
@ -184,7 +184,7 @@ func (rs *Resource) refresh(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
token.Token = uuid.NewV4().String()
|
||||
token.Expiry = time.Now().Add(time.Minute * rs.Token.jwtRefreshExpiry)
|
||||
token.Expiry = time.Now().Add(rs.Token.jwtRefreshExpiry)
|
||||
token.UpdatedAt = time.Now()
|
||||
|
||||
access, refresh, err := rs.Token.GenTokenPair(acc.Claims(), token.Claims())
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ func (a *TokenAuth) GenTokenPair(ca jwtauth.Claims, cr jwtauth.Claims) (string,
|
|||
// CreateJWT returns an access token for provided account claims.
|
||||
func (a *TokenAuth) CreateJWT(c jwtauth.Claims) (string, error) {
|
||||
c.SetIssuedNow()
|
||||
c.SetExpiryIn(a.jwtExpiry * time.Minute)
|
||||
c.SetExpiryIn(a.jwtExpiry)
|
||||
_, tokenString, err := a.JwtAuth.Encode(c)
|
||||
return tokenString, err
|
||||
}
|
||||
|
|
@ -67,7 +67,7 @@ func (a *TokenAuth) CreateJWT(c jwtauth.Claims) (string, error) {
|
|||
// CreateRefreshJWT returns a refresh token for provided token Claims.
|
||||
func (a *TokenAuth) CreateRefreshJWT(c jwtauth.Claims) (string, error) {
|
||||
c.SetIssuedNow()
|
||||
c.SetExpiryIn(time.Minute * a.jwtRefreshExpiry)
|
||||
c.SetExpiryIn(a.jwtRefreshExpiry)
|
||||
_, tokenString, err := a.JwtAuth.Encode(c)
|
||||
return tokenString, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ func (a *LoginTokenAuth) CreateToken(id int) LoginToken {
|
|||
lt := LoginToken{
|
||||
Token: randStringBytes(a.loginTokenLength),
|
||||
AccountID: id,
|
||||
Expiry: time.Now().Add(time.Minute * a.loginTokenExpiry),
|
||||
Expiry: time.Now().Add(a.loginTokenExpiry),
|
||||
}
|
||||
a.add(lt)
|
||||
a.purgeExpired()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue