Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Do not set header X-Goog-User-Project header for the resource google_client_openid_userinfo" #5086

Merged
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
3 changes: 3 additions & 0 deletions .changelog/7112.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
4 changes: 1 addition & 3 deletions google-beta/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ func sendRequestWithTimeout(config *Config, method, project, rawurl, userAgent s
reqHeaders.Set("User-Agent", userAgent)
reqHeaders.Set("Content-Type", "application/json")

if !config.UserProjectOverride {
reqHeaders.Set("X-Goog-User-Project", "")
} else if config.UserProjectOverride && project != "" {
if config.UserProjectOverride && project != "" {
// Pass the project into this fn instead of parsing it from the URL because
// both project names and URLs can have colons in them.
reqHeaders.Set("X-Goog-User-Project", project)
Expand Down
8 changes: 0 additions & 8 deletions google-beta/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,17 +514,9 @@ func multiEnvSearch(ks []string) string {
}

func GetCurrentUserEmail(config *Config, userAgent string) (string, error) {
// When environment variables UserProjectOverride and BillingProject are set for the provider, the header X-Goog-User-Project is set for the API requests.
// But it causes an error when calling GetCurrentUserEmail. It makes sense to not set header X-Goog-User-Project by setting UserProjectOverride
// to false when calling GetCurrentUserEmail, because it does not create a bill.
origUserProjectOverride := config.UserProjectOverride
config.UserProjectOverride = false

// See https://github.com/golang/oauth2/issues/306 for a recommendation to do this from a Go maintainer
// URL retrieved from https://accounts.google.com/.well-known/openid-configuration
res, err := sendRequest(config, "GET", "", "https://openidconnect.googleapis.com/v1/userinfo", userAgent, nil)
config.UserProjectOverride = origUserProjectOverride

if err != nil {
return "", fmt.Errorf("error retrieving userinfo for your provider credentials. have you enabled the 'https://www.googleapis.com/auth/userinfo.email' scope? error: %s", err)
}
Expand Down