-
Notifications
You must be signed in to change notification settings - Fork 992
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
google: add Credentials.UniverseDomain to support TPC
Read and expose universe_domain from service account JSON files in CredentialsFromJSONWithParams to support TPC in 1p clients. Change-Id: I3518a0ec8be5ff7235b946cffd88b26ac8d303cf Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/531715 Run-TryBot: Cody Oss <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Cody Oss <[email protected]>
- Loading branch information
Showing
3 changed files
with
74 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2023 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package google | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
) | ||
|
||
var jwtJSONKeyUniverseDomain = []byte(`{ | ||
"type": "service_account", | ||
"project_id": "fake_project", | ||
"universe_domain": "example.com", | ||
"private_key_id": "268f54e43a1af97cfc71731688434f45aca15c8b", | ||
"private_key": "super secret key", | ||
"client_email": "[email protected]", | ||
"client_id": "gopher.apps.googleusercontent.com", | ||
"auth_uri": "https://accounts.google.com/o/oauth2/auth", | ||
"token_uri": "https://oauth2.googleapis.com/token", | ||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", | ||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gopher%40fake_project.iam.gserviceaccount.com" | ||
}`) | ||
|
||
func TestCredentialsFromJSONWithParams_UniverseDomain(t *testing.T) { | ||
ctx := context.Background() | ||
scope := "https://www.googleapis.com/auth/cloud-platform" | ||
params := CredentialsParams{ | ||
Scopes: []string{scope}, | ||
} | ||
creds, err := CredentialsFromJSONWithParams(ctx, jwtJSONKeyUniverseDomain, params) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if want := "fake_project"; creds.ProjectID != want { | ||
t.Fatalf("got %q, want %q", creds.ProjectID, want) | ||
} | ||
if want := "example.com"; creds.UniverseDomain() != want { | ||
t.Fatalf("got %q, want %q", creds.UniverseDomain(), want) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters