refactor: just try to parse and check expire without verification

This commit is contained in:
Derrick Hammer 2024-02-11 16:26:54 -05:00
parent 4b429e6d59
commit 0cf1b8827a
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 17 additions and 19 deletions

View File

@ -57,17 +57,14 @@ 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 claims, ok := parsedToken.Claims.(jwt.MapClaims); ok && parsedToken.Valid {
if exp, ok := claims["exp"].(float64); ok { if exp, ok := claims["exp"].(float64); ok {
expirationTime := time.Unix(int64(exp), 0) expirationTime := time.Unix(int64(exp), 0)
if time.Now().Before(expirationTime) { if time.Now().Before(expirationTime) {
@ -83,6 +80,7 @@ func (o oauth) loadToken(config *oauth2.Config) {
o.logger.Info("Token is expired, ignoring") o.logger.Info("Token is expired, ignoring")
} }
} }
}
o.refresher = config.TokenSource(context.Background(), token) o.refresher = config.TokenSource(context.Background(), token)
} }