googleauth 0.14.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +11 -0
  3. data/CHANGELOG.md +72 -10
  4. data/README.md +48 -13
  5. data/SECURITY.md +7 -0
  6. data/lib/googleauth/application_default.rb +10 -25
  7. data/lib/googleauth/client_id.rb +10 -25
  8. data/lib/googleauth/compute_engine.rb +16 -30
  9. data/lib/googleauth/credentials.rb +178 -74
  10. data/lib/googleauth/credentials_loader.rb +23 -44
  11. data/lib/googleauth/default_credentials.rb +10 -25
  12. data/lib/googleauth/iam.rb +11 -26
  13. data/lib/googleauth/id_tokens/errors.rb +9 -23
  14. data/lib/googleauth/id_tokens/key_sources.rb +26 -38
  15. data/lib/googleauth/id_tokens/verifier.rb +16 -32
  16. data/lib/googleauth/id_tokens.rb +9 -23
  17. data/lib/googleauth/json_key_reader.rb +10 -25
  18. data/lib/googleauth/scope_util.rb +11 -26
  19. data/lib/googleauth/service_account.rb +60 -59
  20. data/lib/googleauth/signet.rb +22 -28
  21. data/lib/googleauth/stores/file_token_store.rb +11 -25
  22. data/lib/googleauth/stores/redis_token_store.rb +11 -25
  23. data/lib/googleauth/token_store.rb +10 -25
  24. data/lib/googleauth/user_authorizer.rb +10 -25
  25. data/lib/googleauth/user_refresh.rb +15 -27
  26. data/lib/googleauth/version.rb +11 -26
  27. data/lib/googleauth/web_user_authorizer.rb +14 -32
  28. data/lib/googleauth.rb +10 -25
  29. metadata +26 -97
  30. data/.github/CODEOWNERS +0 -7
  31. data/.github/CONTRIBUTING.md +0 -74
  32. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -36
  33. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -21
  34. data/.github/ISSUE_TEMPLATE/support_request.md +0 -7
  35. data/.gitignore +0 -36
  36. data/.kokoro/build.bat +0 -16
  37. data/.kokoro/build.sh +0 -4
  38. data/.kokoro/continuous/common.cfg +0 -24
  39. data/.kokoro/continuous/linux.cfg +0 -25
  40. data/.kokoro/continuous/osx.cfg +0 -8
  41. data/.kokoro/continuous/post.cfg +0 -30
  42. data/.kokoro/continuous/windows.cfg +0 -29
  43. data/.kokoro/osx.sh +0 -4
  44. data/.kokoro/presubmit/common.cfg +0 -24
  45. data/.kokoro/presubmit/linux.cfg +0 -24
  46. data/.kokoro/presubmit/osx.cfg +0 -8
  47. data/.kokoro/presubmit/windows.cfg +0 -29
  48. data/.kokoro/release.cfg +0 -94
  49. data/.kokoro/trampoline.bat +0 -10
  50. data/.kokoro/trampoline.sh +0 -4
  51. data/.repo-metadata.json +0 -5
  52. data/.rspec +0 -2
  53. data/.rubocop.yml +0 -19
  54. data/Gemfile +0 -30
  55. data/Rakefile +0 -132
  56. data/googleauth.gemspec +0 -38
  57. data/integration/helper.rb +0 -31
  58. data/integration/id_tokens/key_source_test.rb +0 -74
  59. data/rakelib/devsite_builder.rb +0 -45
  60. data/rakelib/link_checker.rb +0 -64
  61. data/rakelib/repo_metadata.rb +0 -59
  62. data/spec/googleauth/apply_auth_examples.rb +0 -171
  63. data/spec/googleauth/client_id_spec.rb +0 -160
  64. data/spec/googleauth/compute_engine_spec.rb +0 -160
  65. data/spec/googleauth/credentials_spec.rb +0 -478
  66. data/spec/googleauth/get_application_default_spec.rb +0 -286
  67. data/spec/googleauth/iam_spec.rb +0 -80
  68. data/spec/googleauth/scope_util_spec.rb +0 -77
  69. data/spec/googleauth/service_account_spec.rb +0 -489
  70. data/spec/googleauth/signet_spec.rb +0 -142
  71. data/spec/googleauth/stores/file_token_store_spec.rb +0 -57
  72. data/spec/googleauth/stores/redis_token_store_spec.rb +0 -50
  73. data/spec/googleauth/stores/store_examples.rb +0 -58
  74. data/spec/googleauth/user_authorizer_spec.rb +0 -343
  75. data/spec/googleauth/user_refresh_spec.rb +0 -359
  76. data/spec/googleauth/web_user_authorizer_spec.rb +0 -172
  77. data/spec/spec_helper.rb +0 -92
  78. data/test/helper.rb +0 -33
  79. data/test/id_tokens/key_sources_test.rb +0 -240
  80. data/test/id_tokens/verifier_test.rb +0 -269
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8846e57d325ff993c15ca691e299b9c2c4b7472b1b0a9e905b36cdb99216e061
4
- data.tar.gz: 2fcee29e36a6fd57420b9cd0106cf3ab73bf447e94e2f6bdce61a973d256cd5e
3
+ metadata.gz: 0bc48c47d78d7ec955a2a5557fc8f1cff502a28dd1e18c5af3fc566be5743171
4
+ data.tar.gz: 220a8fed81a73d5bc93a2fca2951a749b9469cb769a198cf13564ad7f714ac90
5
5
  SHA512:
6
- metadata.gz: dd54bce055240fc1db34ccfe2850ab49f23b17f55f5336dfeccf380c2f93b8b9e29100a1c53f360564e8387805a9c4bf74d09eb2ca58b5bda666cdab3b061f45
7
- data.tar.gz: 27dae4439e8163194604e912918709d2cd623c61856f70f7c350b08dfac010fdff50ad703934b88631c2759dcf7e5aab5b315a884cb160790c153115ee88bdfe
6
+ metadata.gz: 73f52ffce21a05e15102b54aabbcb3cb199d32e9caf318b125b48b6caeddc01f77c3de4ea09513b0b1e9e503c912e55adf5864b4295b86af0620aa0c7df25df4
7
+ data.tar.gz: 7ec107faa35d72aa1fd8e79b86b30df9acf061ce86ac52641bc12b69391f0b4f2adde8021b908327e379dee65c1e2ed7ed1b203e629ca1f4d25a988e80c31eb2
data/.yardopts ADDED
@@ -0,0 +1,11 @@
1
+ --no-private
2
+ --title=Google Auth
3
+ --markup markdown
4
+ --markup-provider redcarpet
5
+
6
+ ./lib/**/*.rb
7
+ -
8
+ README.md
9
+ CHANGELOG.md
10
+ CODE_OF_CONDUCT.md
11
+ LICENSE
data/CHANGELOG.md CHANGED
@@ -1,5 +1,77 @@
1
1
  # Release History
2
2
 
3
+ ### 1.3.0 (2022-10-18)
4
+
5
+ #### Features
6
+
7
+ * Use OpenSSL 3.0 compatible interfaces for IDTokens ([#397](https://github.com/googleapis/google-auth-library-ruby/issues/397))
8
+
9
+ ### 1.2.0 (2022-06-23)
10
+
11
+ * Updated minimum Ruby version to 2.6
12
+
13
+ ### 1.1.3 (2022-04-20)
14
+
15
+ #### Documentation
16
+
17
+ * Add README instructions for 3-Legged OAuth with a service account
18
+
19
+ ### 1.1.2 (2022-02-22)
20
+
21
+ #### Bug Fixes
22
+
23
+ * Support Faraday 2
24
+
25
+ ### 1.1.1 (2022-02-14)
26
+
27
+ #### Bug Fixes
28
+
29
+ * add quota_project to user refresh credentials
30
+
31
+ ### 1.1.0 (2021-10-24)
32
+
33
+ #### Features
34
+
35
+ * Support short-lived tokens in Credentials
36
+
37
+ ### 1.0.0 (2021-09-27)
38
+
39
+ Bumped version to 1.0.0. Releases from this point will follow semver.
40
+
41
+ * Allow dependency on future 1.x versions of signet
42
+ * Prevented gcloud from authenticating on the console when getting the gcloud project
43
+
44
+ ### 0.17.1 (2021-09-01)
45
+
46
+ * Updates to gem metadata
47
+
48
+ ### 0.17.0 (2021-07-30)
49
+
50
+ * Allow scopes to be self-signed into jwts
51
+
52
+ ### 0.16.2 (2021-04-28)
53
+
54
+ * Stop attempting to get the project from gcloud when applying self-signed JWTs
55
+
56
+ ### 0.16.1 (2021-04-01)
57
+
58
+ * Accept application/text content-type for plain idtoken response
59
+
60
+ ### 0.16.0 (2021-03-04)
61
+
62
+ * Drop support for Ruby 2.4 and add support for Ruby 3.0
63
+
64
+ ### 0.15.1 (2021-02-08)
65
+
66
+ * Fix crash when using a client credential without any paths or env_vars set
67
+
68
+ ### 0.15.0 (2021-01-26)
69
+
70
+ * Credential parameters inherit from superclasses
71
+ * Service accounts apply a self-signed JWT if scopes are marked as default
72
+ * Retry fetch_access_token when GCE metadata server returns unexpected errors
73
+ * Support correct service account and user refresh behavior for custom credential env variables
74
+
3
75
  ### 0.14.0 / 2020-10-09
4
76
 
5
77
  * Honor GCE_METADATA_HOST environment variable
@@ -108,7 +180,6 @@ Note: This release now requires Ruby 2.4 or later
108
180
 
109
181
  * Change header name emitted by `Client#apply` from "Authorization" to "authorization" ([@murgatroid99][])
110
182
  * Fix ADC not working on some windows machines ([@vsubramani][])
111
- [#55](https://github.com/google/google-auth-library-ruby/issues/55)
112
183
 
113
184
  ### 0.5.0 / 2015-10-12
114
185
 
@@ -118,19 +189,10 @@ Note: This release now requires Ruby 2.4 or later
118
189
  ### 0.4.2 / 2015-08-05
119
190
 
120
191
  * Updated UserRefreshCredentials hash to use string keys ([@haabaato][])
121
- [#36](https://github.com/google/google-auth-library-ruby/issues/36)
122
-
123
192
  * Add support for a system default credentials file. ([@mr-salty][])
124
- [#33](https://github.com/google/google-auth-library-ruby/issues/33)
125
-
126
193
  * Fix bug when loading credentials from ENV ([@dwilkie][])
127
- [#31](https://github.com/google/google-auth-library-ruby/issues/31)
128
-
129
194
  * Relax the constraint of dependent version of multi_json ([@igrep][])
130
- [#30](https://github.com/google/google-auth-library-ruby/issues/30)
131
-
132
195
  * Enables passing credentials via environment variables. ([@haabaato][])
133
- [#27](https://github.com/google/google-auth-library-ruby/issues/27)
134
196
 
135
197
  ### 0.4.1 / 2015-04-25
136
198
 
data/README.md CHANGED
@@ -14,11 +14,6 @@
14
14
  This is Google's officially supported ruby client library for using OAuth 2.0
15
15
  authorization and authentication with Google APIs.
16
16
 
17
- ## Alpha
18
-
19
- This library is in Alpha. We will make an effort to support the library, but
20
- we reserve the right to make incompatible changes when necessary.
21
-
22
17
  ## Install
23
18
 
24
19
  Be sure `https://rubygems.org/` is in your gem sources.
@@ -116,6 +111,7 @@ token_store = Google::Auth::Stores::FileTokenStore.new(
116
111
  :file => '/path/to/tokens.yaml')
117
112
  authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)
118
113
 
114
+ user_id = ENV['USER']
119
115
  credentials = authorizer.get_credentials(user_id)
120
116
  if credentials.nil?
121
117
  url = authorizer.get_authorization_url(base_url: OOB_URI )
@@ -140,6 +136,43 @@ authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
140
136
  authorizer.fetch_access_token!
141
137
  ```
142
138
 
139
+ You can also use a JSON keyfile by setting the `GOOGLE_APPLICATION_CREDENTIALS` environment variable.
140
+
141
+ ```bash
142
+ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account_json_key.json
143
+ ```
144
+
145
+ ```ruby
146
+ require 'googleauth'
147
+ require 'google/apis/drive_v3'
148
+
149
+ Drive = ::Google::Apis::DriveV3
150
+ drive = Drive::DriveService.new
151
+
152
+ scope = 'https://www.googleapis.com/auth/drive'
153
+
154
+ authorizer = Google::Auth::ServiceAccountCredentials.from_env(scope: scope)
155
+ drive.authorization = authorizer
156
+
157
+ list_files = drive.list_files()
158
+ ```
159
+
160
+ ### 3-Legged OAuth with a Service Account
161
+
162
+ This is similar to regular service account authorization (see [this answer](https://support.google.com/a/answer/2538798?hl=en) for more details on the differences), but you'll need to indicate which user your service account is impersonating by manually updating the `sub` field.
163
+
164
+ ```ruby
165
+ scope = 'https://www.googleapis.com/auth/androidpublisher'
166
+
167
+ authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
168
+ json_key_io: File.open('/path/to/service_account_json_key.json'),
169
+ scope: scope
170
+ )
171
+ authorizer.update!(sub: "email-to-impersonate@your-domain.com")
172
+
173
+ authorizer.fetch_access_token!
174
+ ```
175
+
143
176
  ### Example (Environment Variables)
144
177
 
145
178
  ```bash
@@ -182,17 +215,19 @@ Custom storage implementations can also be used. See
182
215
 
183
216
  ## Supported Ruby Versions
184
217
 
185
- This library requires Ruby 2.4 or later.
218
+ This library is supported on Ruby 2.6+.
186
219
 
187
- In general, this library supports Ruby versions that are considered current and
188
- supported by Ruby Core (that is, Ruby versions that are either in normal
189
- maintenance or in security maintenance).
190
- See https://www.ruby-lang.org/en/downloads/branches/ for further details.
220
+ Google provides official support for Ruby versions that are actively supported
221
+ by Ruby Corethat is, Ruby versions that are either in normal maintenance or
222
+ in security maintenance, and not end of life. Older versions of Ruby _may_
223
+ still work, but are unsupported and not recommended. See
224
+ https://www.ruby-lang.org/en/downloads/branches/ for details about the Ruby
225
+ support schedule.
191
226
 
192
227
  ## License
193
228
 
194
229
  This library is licensed under Apache 2.0. Full license text is
195
- available in [COPYING][copying].
230
+ available in [LICENSE][license].
196
231
 
197
232
  ## Contributing
198
233
 
@@ -207,5 +242,5 @@ hesitate to
207
242
  about the client or APIs on [StackOverflow](http://stackoverflow.com).
208
243
 
209
244
  [application default credentials]: https://developers.google.com/accounts/docs/application-default-credentials
210
- [contributing]: https://github.com/googleapis/google-auth-library-ruby/tree/master/.github/CONTRIBUTING.md
211
- [copying]: https://github.com/googleapis/google-auth-library-ruby/tree/master/COPYING
245
+ [contributing]: https://github.com/googleapis/google-auth-library-ruby/tree/main/.github/CONTRIBUTING.md
246
+ [license]: https://github.com/googleapis/google-auth-library-ruby/tree/main/LICENSE
data/SECURITY.md ADDED
@@ -0,0 +1,7 @@
1
+ # Security Policy
2
+
3
+ To report a security issue, please use [g.co/vulnz](https://g.co/vulnz).
4
+
5
+ The Google Security Team will respond within 5 working days of your report on g.co/vulnz.
6
+
7
+ We use g.co/vulnz for our intake, and do coordination and disclosure here using GitHub Security Advisory to privately discuss and fix the issue.
@@ -1,31 +1,16 @@
1
- # Copyright 2015, Google Inc.
2
- # All rights reserved.
1
+ # Copyright 2015 Google, Inc.
3
2
  #
4
- # Redistribution and use in source and binary forms, with or without
5
- # modification, are permitted provided that the following conditions are
6
- # met:
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
7
6
  #
8
- # * Redistributions of source code must retain the above copyright
9
- # notice, this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above
11
- # copyright notice, this list of conditions and the following disclaimer
12
- # in the documentation and/or other materials provided with the
13
- # distribution.
14
- # * Neither the name of Google Inc. nor the names of its
15
- # contributors may be used to endorse or promote products derived from
16
- # this software without specific prior written permission.
7
+ # http://www.apache.org/licenses/LICENSE-2.0
17
8
  #
18
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
- # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
- # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
- # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
- # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
- # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
- # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
29
14
 
30
15
  require "googleauth/compute_engine"
31
16
  require "googleauth/default_credentials"
@@ -1,31 +1,16 @@
1
- # Copyright 2014, Google Inc.
2
- # All rights reserved.
1
+ # Copyright 2014 Google, Inc.
3
2
  #
4
- # Redistribution and use in source and binary forms, with or without
5
- # modification, are permitted provided that the following conditions are
6
- # met:
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
7
6
  #
8
- # * Redistributions of source code must retain the above copyright
9
- # notice, this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above
11
- # copyright notice, this list of conditions and the following disclaimer
12
- # in the documentation and/or other materials provided with the
13
- # distribution.
14
- # * Neither the name of Google Inc. nor the names of its
15
- # contributors may be used to endorse or promote products derived from
16
- # this software without specific prior written permission.
7
+ # http://www.apache.org/licenses/LICENSE-2.0
17
8
  #
18
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
- # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
- # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
- # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
- # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
- # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
- # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
29
14
 
30
15
  require "multi_json"
31
16
  require "googleauth/credentials_loader"
@@ -1,31 +1,16 @@
1
- # Copyright 2015, Google Inc.
2
- # All rights reserved.
1
+ # Copyright 2015 Google, Inc.
3
2
  #
4
- # Redistribution and use in source and binary forms, with or without
5
- # modification, are permitted provided that the following conditions are
6
- # met:
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
7
6
  #
8
- # * Redistributions of source code must retain the above copyright
9
- # notice, this list of conditions and the following disclaimer.
10
- # * Redistributions in binary form must reproduce the above
11
- # copyright notice, this list of conditions and the following disclaimer
12
- # in the documentation and/or other materials provided with the
13
- # distribution.
14
- # * Neither the name of Google Inc. nor the names of its
15
- # contributors may be used to endorse or promote products derived from
16
- # this software without specific prior written permission.
7
+ # http://www.apache.org/licenses/LICENSE-2.0
17
8
  #
18
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
- # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
- # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
- # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
- # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
- # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
- # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
29
14
 
30
15
  require "faraday"
31
16
  require "googleauth/signet"
@@ -108,21 +93,22 @@ module Google
108
93
  uri = target_audience ? GCECredentials.compute_id_token_uri : GCECredentials.compute_auth_token_uri
109
94
  query = target_audience ? { "audience" => target_audience, "format" => "full" } : {}
110
95
  query[:scopes] = Array(scope).join "," if scope
111
- headers = { "Metadata-Flavor" => "Google" }
112
- resp = c.get uri, query, headers
96
+ resp = c.get uri, query, "Metadata-Flavor" => "Google"
113
97
  case resp.status
114
98
  when 200
115
99
  content_type = resp.headers["content-type"]
116
- if content_type == "text/html"
100
+ if ["text/html", "application/text"].include? content_type
117
101
  { (target_audience ? "id_token" : "access_token") => resp.body }
118
102
  else
119
103
  Signet::OAuth2.parse_credentials resp.body, content_type
120
104
  end
105
+ when 403, 500
106
+ msg = "Unexpected error code #{resp.status} #{UNEXPECTED_ERROR_SUFFIX}"
107
+ raise Signet::UnexpectedStatusError, msg
121
108
  when 404
122
109
  raise Signet::AuthorizationError, NO_METADATA_SERVER_ERROR
123
110
  else
124
- msg = "Unexpected error code #{resp.status}" \
125
- "#{UNEXPECTED_ERROR_SUFFIX}"
111
+ msg = "Unexpected error code #{resp.status} #{UNEXPECTED_ERROR_SUFFIX}"
126
112
  raise Signet::AuthorizationError, msg
127
113
  end
128
114
  end