fix: Fix errors when requesting an access token for multiple scopes
This commit is contained in:
parent
3cdb5a8de7
commit
6f71d62a6a
|
@ -107,7 +107,7 @@ module Google
|
||||||
retry_with_error do
|
retry_with_error do
|
||||||
uri = target_audience ? GCECredentials.compute_id_token_uri : GCECredentials.compute_auth_token_uri
|
uri = target_audience ? GCECredentials.compute_id_token_uri : GCECredentials.compute_auth_token_uri
|
||||||
query = target_audience ? { "audience" => target_audience, "format" => "full" } : {}
|
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" }
|
headers = { "Metadata-Flavor" => "Google" }
|
||||||
resp = c.get uri, query, headers
|
resp = c.get uri, query, headers
|
||||||
case resp.status
|
case resp.status
|
||||||
|
|
|
@ -53,7 +53,7 @@ describe Google::Auth::GCECredentials do
|
||||||
"expires_in" => 3600)
|
"expires_in" => 3600)
|
||||||
|
|
||||||
uri = MD_ACCESS_URI
|
uri = MD_ACCESS_URI
|
||||||
uri += "?scopes=#{opts[:scope]}" if opts[:scope]
|
uri += "?scopes=#{Array(opts[:scope]).join ','}" if opts[:scope]
|
||||||
|
|
||||||
stub_request(:get, uri)
|
stub_request(:get, uri)
|
||||||
.with(headers: { "Metadata-Flavor" => "Google" })
|
.with(headers: { "Metadata-Flavor" => "Google" })
|
||||||
|
@ -74,9 +74,9 @@ describe Google::Auth::GCECredentials do
|
||||||
context "metadata is unavailable" do
|
context "metadata is unavailable" do
|
||||||
describe "#fetch_access_token" do
|
describe "#fetch_access_token" do
|
||||||
it "should pass scopes when requesting an access token" do
|
it "should pass scopes when requesting an access token" do
|
||||||
scope = "https://www.googleapis.com/auth/drive"
|
scopes = ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/bigtable.data"]
|
||||||
stub = make_auth_stubs access_token: "1/abcdef1234567890", scope: scope
|
stub = make_auth_stubs access_token: "1/abcdef1234567890", scope: scopes
|
||||||
@client = GCECredentials.new(scope: [scope])
|
@client = GCECredentials.new(scope: scopes)
|
||||||
@client.fetch_access_token!
|
@client.fetch_access_token!
|
||||||
expect(stub).to have_been_requested
|
expect(stub).to have_been_requested
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue