refactor: just try to parse and check expire without verification
This commit is contained in:
parent
4b429e6d59
commit
0cf1b8827a
36
api/oauth.go
36
api/oauth.go
|
@ -57,30 +57,28 @@ func (o oauth) loadToken(config *oauth2.Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if o.token != nil {
|
if o.token != nil {
|
||||||
parsedToken, err := jwt.Parse(o.cfg.Oauth.Token, func(token *jwt.Token) (interface{}, error) {
|
valid := false
|
||||||
return nil, nil
|
parseToken, _, err := new(jwt.Parser).ParseUnverified(o.cfg.Oauth.Token, jwt.MapClaims{})
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
o.logger.Fatal("Error parsing token", zap.Error(err))
|
o.logger.Error("Error parsing token", zap.Error(err))
|
||||||
}
|
} else {
|
||||||
|
// Assert the token's claims to the desired type (MapClaims in this case)
|
||||||
valid := false
|
if claims, ok := parseToken.Claims.(jwt.MapClaims); ok {
|
||||||
|
if exp, ok := claims["exp"].(float64); ok {
|
||||||
if claims, ok := parsedToken.Claims.(jwt.MapClaims); ok && parsedToken.Valid {
|
expirationTime := time.Unix(int64(exp), 0)
|
||||||
if exp, ok := claims["exp"].(float64); ok {
|
if time.Now().Before(expirationTime) {
|
||||||
expirationTime := time.Unix(int64(exp), 0)
|
valid = true
|
||||||
if time.Now().Before(expirationTime) {
|
o.token.Expiry = expirationTime
|
||||||
valid = true
|
}
|
||||||
o.token.Expiry = expirationTime
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if valid {
|
if valid {
|
||||||
token = o.token
|
token = o.token
|
||||||
} else {
|
} else {
|
||||||
o.logger.Info("Token is expired, ignoring")
|
o.logger.Info("Token is expired, ignoring")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue