fix(auth): include full scopes when refreshing Google OAuth token

The refresh was using reduced scopes (openid profile email) instead of the
original scopes (cloud-platform, userinfo.email, etc.). This caused Google
to return tokens with insufficient permissions, resulting in
'Request had insufficient authentication scopes' errors.

Now uses cfg.Scopes (the original OAuth scopes) when refreshing to
maintain the full permission set.
This commit is contained in:
Vishnuvardhan Reddy 2026-02-26 15:22:17 +00:00
parent 49642df1b7
commit 8cbdf5d1f2

View file

@ -326,11 +326,17 @@ func RefreshAccessToken(cred *AuthCredential, cfg OAuthProviderConfig) (*AuthCre
return nil, fmt.Errorf("no refresh token available") return nil, fmt.Errorf("no refresh token available")
} }
// Use the same scopes as the original OAuth flow to prevent scope reduction
scope := cfg.Scopes
if scope == "" {
scope = "openid profile email"
}
data := url.Values{ data := url.Values{
"client_id": {cfg.ClientID}, "client_id": {cfg.ClientID},
"grant_type": {"refresh_token"}, "grant_type": {"refresh_token"},
"refresh_token": {cred.RefreshToken}, "refresh_token": {cred.RefreshToken},
"scope": {"openid profile email"}, "scope": {scope},
} }
if cfg.ClientSecret != "" { if cfg.ClientSecret != "" {
data.Set("client_secret", cfg.ClientSecret) data.Set("client_secret", cfg.ClientSecret)