googleauth 1.14.0 → 1.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/Credentials.md +110 -0
  4. data/Errors.md +152 -0
  5. data/lib/googleauth/api_key.rb +9 -0
  6. data/lib/googleauth/application_default.rb +3 -1
  7. data/lib/googleauth/base_client.rb +5 -0
  8. data/lib/googleauth/bearer_token.rb +16 -2
  9. data/lib/googleauth/client_id.rb +9 -5
  10. data/lib/googleauth/compute_engine.rb +64 -18
  11. data/lib/googleauth/credentials.rb +67 -35
  12. data/lib/googleauth/credentials_loader.rb +24 -4
  13. data/lib/googleauth/default_credentials.rb +64 -32
  14. data/lib/googleauth/errors.rb +117 -0
  15. data/lib/googleauth/external_account/aws_credentials.rb +85 -18
  16. data/lib/googleauth/external_account/base_credentials.rb +31 -2
  17. data/lib/googleauth/external_account/external_account_utils.rb +15 -4
  18. data/lib/googleauth/external_account/identity_pool_credentials.rb +40 -15
  19. data/lib/googleauth/external_account/pluggable_credentials.rb +34 -19
  20. data/lib/googleauth/external_account.rb +35 -6
  21. data/lib/googleauth/iam.rb +19 -3
  22. data/lib/googleauth/id_tokens/errors.rb +13 -7
  23. data/lib/googleauth/id_tokens/key_sources.rb +13 -7
  24. data/lib/googleauth/id_tokens/verifier.rb +2 -3
  25. data/lib/googleauth/id_tokens.rb +4 -4
  26. data/lib/googleauth/impersonated_service_account.rb +64 -17
  27. data/lib/googleauth/json_key_reader.rb +11 -2
  28. data/lib/googleauth/oauth2/sts_client.rb +9 -4
  29. data/lib/googleauth/scope_util.rb +1 -1
  30. data/lib/googleauth/service_account.rb +37 -10
  31. data/lib/googleauth/service_account_jwt_header.rb +9 -2
  32. data/lib/googleauth/signet.rb +24 -6
  33. data/lib/googleauth/user_authorizer.rb +35 -7
  34. data/lib/googleauth/user_refresh.rb +42 -16
  35. data/lib/googleauth/version.rb +1 -1
  36. data/lib/googleauth/web_user_authorizer.rb +46 -9
  37. data/lib/googleauth.rb +1 -0
  38. metadata +8 -5
@@ -13,6 +13,7 @@
13
13
  # limitations under the License.
14
14
 
15
15
  require "multi_json"
16
+ require "googleauth/errors"
16
17
  require "googleauth/signet"
17
18
  require "googleauth/user_authorizer"
18
19
  require "googleauth/user_refresh"
@@ -79,6 +80,8 @@ module Google
79
80
  #
80
81
  # @param [Rack::Request] request
81
82
  # Current request
83
+ # @return [String, nil]
84
+ # Redirect URI if successfully extracted, nil otherwise
82
85
  def self.handle_auth_callback_deferred request
83
86
  callback_state, redirect_uri = extract_callback_state request
84
87
  request.session[CALLBACK_STATE_KEY] = MultiJson.dump callback_state
@@ -151,11 +154,13 @@ module Google
151
154
  # Optional key-values to be returned to the oauth callback.
152
155
  # @return [String]
153
156
  # Authorization url
157
+ # @raise [Google::Auth::InitializationError]
158
+ # If request is nil or request.session is nil
154
159
  def get_authorization_url options = {}
155
160
  options = options.dup
156
161
  request = options[:request]
157
- raise NIL_REQUEST_ERROR if request.nil?
158
- raise NIL_SESSION_ERROR if request.session.nil?
162
+ raise InitializationError, NIL_REQUEST_ERROR if request.nil?
163
+ raise InitializationError, NIL_SESSION_ERROR if request.session.nil?
159
164
 
160
165
  state = options[:state] || {}
161
166
 
@@ -181,9 +186,9 @@ module Google
181
186
  # requested scopes
182
187
  # @return [Google::Auth::UserRefreshCredentials]
183
188
  # Stored credentials, nil if none present
184
- # @raise [Signet::AuthorizationError]
185
- # May raise an error if an authorization code is present in the session
186
- # and exchange of the code fails
189
+ # @raise [Google::Auth::AuthorizationError]
190
+ # If the authorization code is missing, there's an error in the request,
191
+ # or the state token doesn't match
187
192
  def get_credentials user_id, request = nil, scope = nil
188
193
  if request&.session&.key? CALLBACK_STATE_KEY
189
194
  # Note - in theory, no need to check required scope as this is
@@ -202,6 +207,12 @@ module Google
202
207
  end
203
208
  end
204
209
 
210
+ # Extract the callback state from the request
211
+ #
212
+ # @param [Rack::Request] request
213
+ # Current request
214
+ # @return [Array<Hash, String>]
215
+ # Callback state and redirect URI
205
216
  def self.extract_callback_state request
206
217
  state = MultiJson.load(request.params[STATE_PARAM] || "{}")
207
218
  redirect_uri = state[CURRENT_URI_KEY]
@@ -214,6 +225,15 @@ module Google
214
225
  [callback_state, redirect_uri]
215
226
  end
216
227
 
228
+ # Returns the principal identifier for this web authorizer
229
+ # This is a class method that returns a symbol since
230
+ # we might not have a client_id in the static callback context
231
+ #
232
+ # @return [Symbol] The symbol for web user authorization
233
+ def self.principal
234
+ :web_user_authorization
235
+ end
236
+
217
237
  # Verifies the results of an authorization callback
218
238
  #
219
239
  # @param [Hash] state
@@ -224,13 +244,30 @@ module Google
224
244
  # Error message if failed
225
245
  # @param [Rack::Request] request
226
246
  # Current request
247
+ # @raise [Google::Auth::AuthorizationError]
248
+ # If the authorization code is missing, there's an error in the callback state,
249
+ # or the state token doesn't match
227
250
  def self.validate_callback_state state, request
228
- raise Signet::AuthorizationError, MISSING_AUTH_CODE_ERROR if state[AUTH_CODE_KEY].nil?
251
+ if state[AUTH_CODE_KEY].nil?
252
+ raise AuthorizationError.with_details(
253
+ MISSING_AUTH_CODE_ERROR,
254
+ credential_type_name: name,
255
+ principal: principal
256
+ )
257
+ end
258
+
229
259
  if state[ERROR_CODE_KEY]
230
- raise Signet::AuthorizationError,
231
- format(AUTHORIZATION_ERROR, state[ERROR_CODE_KEY])
260
+ raise AuthorizationError.with_details(
261
+ format(AUTHORIZATION_ERROR, state[ERROR_CODE_KEY]),
262
+ credential_type_name: name,
263
+ principal: principal
264
+ )
232
265
  elsif request.session[XSRF_KEY] != state[SESSION_ID_KEY]
233
- raise Signet::AuthorizationError, INVALID_STATE_TOKEN_ERROR
266
+ raise AuthorizationError.with_details(
267
+ INVALID_STATE_TOKEN_ERROR,
268
+ credential_type_name: name,
269
+ principal: principal
270
+ )
234
271
  end
235
272
  end
236
273
 
data/lib/googleauth.rb CHANGED
@@ -18,6 +18,7 @@ require "googleauth/bearer_token"
18
18
  require "googleauth/client_id"
19
19
  require "googleauth/credentials"
20
20
  require "googleauth/default_credentials"
21
+ require "googleauth/errors"
21
22
  require "googleauth/external_account"
22
23
  require "googleauth/id_tokens"
23
24
  require "googleauth/impersonated_service_account"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googleauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.0
4
+ version: 1.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google LLC
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-14 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: faraday
@@ -66,7 +66,7 @@ dependencies:
66
66
  version: '1.4'
67
67
  - - "<"
68
68
  - !ruby/object:Gem::Version
69
- version: '3.0'
69
+ version: '4.0'
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '1.4'
77
77
  - - "<"
78
78
  - !ruby/object:Gem::Version
79
- version: '3.0'
79
+ version: '4.0'
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: multi_json
82
82
  requirement: !ruby/object:Gem::Requirement
@@ -142,6 +142,8 @@ files:
142
142
  - ".yardopts"
143
143
  - CHANGELOG.md
144
144
  - CODE_OF_CONDUCT.md
145
+ - Credentials.md
146
+ - Errors.md
145
147
  - LICENSE
146
148
  - README.md
147
149
  - SECURITY.md
@@ -155,6 +157,7 @@ files:
155
157
  - lib/googleauth/credentials.rb
156
158
  - lib/googleauth/credentials_loader.rb
157
159
  - lib/googleauth/default_credentials.rb
160
+ - lib/googleauth/errors.rb
158
161
  - lib/googleauth/external_account.rb
159
162
  - lib/googleauth/external_account/aws_credentials.rb
160
163
  - lib/googleauth/external_account/base_credentials.rb
@@ -202,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
205
  - !ruby/object:Gem::Version
203
206
  version: '0'
204
207
  requirements: []
205
- rubygems_version: 3.6.5
208
+ rubygems_version: 3.6.9
206
209
  specification_version: 4
207
210
  summary: Google Auth Library for Ruby
208
211
  test_files: []