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