Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/auth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ func RefreshAccessToken(cred *AuthCredential, cfg OAuthProviderConfig) (*AuthCre
"client_id": {cfg.ClientID},
"grant_type": {"refresh_token"},
"refresh_token": {cred.RefreshToken},
"scope": {"openid profile email"},
"scope": {cfg.Scopes},
}
if cfg.ClientSecret != "" {
data.Set("client_secret", cfg.ClientSecret)
Expand Down
7 changes: 7 additions & 0 deletions pkg/auth/oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ func TestExchangeCodeForTokens(t *testing.T) {
}

func TestRefreshAccessToken(t *testing.T) {
expectedScope := "https://www.googleapis.com/auth/cloud-platform custom-scope"

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/oauth/token" {
http.Error(w, "not found", http.StatusNotFound)
Expand All @@ -243,6 +245,10 @@ func TestRefreshAccessToken(t *testing.T) {
return
}

if gotScope := r.FormValue("scope"); gotScope != expectedScope {
t.Errorf("Server received scope = %q, want %q", gotScope, expectedScope)
}

resp := map[string]any{
"access_token": "refreshed-access-token",
"refresh_token": "refreshed-refresh-token",
Expand All @@ -255,6 +261,7 @@ func TestRefreshAccessToken(t *testing.T) {
cfg := OAuthProviderConfig{
Issuer: server.URL,
ClientID: "test-client",
Scopes: expectedScope,
}

cred := &AuthCredential{
Expand Down