fix: Fix errors when requesting an access token for multiple scopes

This commit is contained in:
Daniel Azuma 2020-10-09 09:51:49 -07:00 committed by GitHub
parent 3cdb5a8de7
commit 6f71d62a6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -107,7 +107,7 @@ module Google
retry_with_error do
uri = target_audience ? GCECredentials.compute_id_token_uri : GCECredentials.compute_auth_token_uri
query = target_audience ? { "audience" => target_audience, "format" => "full" } : {}
query[:scopes] = Array(scope).join " " if scope
query[:scopes] = Array(scope).join "," if scope
headers = { "Metadata-Flavor" => "Google" }
resp = c.get uri, query, headers
case resp.status

View File

@ -53,7 +53,7 @@ describe Google::Auth::GCECredentials do
"expires_in" => 3600)
uri = MD_ACCESS_URI
uri += "?scopes=#{opts[:scope]}" if opts[:scope]
uri += "?scopes=#{Array(opts[:scope]).join ','}" if opts[:scope]
stub_request(:get, uri)
.with(headers: { "Metadata-Flavor" => "Google" })
@ -74,9 +74,9 @@ describe Google::Auth::GCECredentials do
context "metadata is unavailable" do
describe "#fetch_access_token" do
it "should pass scopes when requesting an access token" do
scope = "https://www.googleapis.com/auth/drive"
stub = make_auth_stubs access_token: "1/abcdef1234567890", scope: scope
@client = GCECredentials.new(scope: [scope])
scopes = ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/bigtable.data"]
stub = make_auth_stubs access_token: "1/abcdef1234567890", scope: scopes
@client = GCECredentials.new(scope: scopes)
@client.fetch_access_token!
expect(stub).to have_been_requested
end