googleauth 1.17.2 → 1.17.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc45e207ab32f63ca0badeb96e1706bc80d38931ff0b69caa0a9a111163aa340
4
- data.tar.gz: 8de82f27d3a8df7a71d0d11ebae8e814a60a3fc963f26825e1c4d420c910dc44
3
+ metadata.gz: 7c73c744b267dbdafe6b4b3366fe629ca7f86774c6c56726b108f38ac3593ee7
4
+ data.tar.gz: 2b5b379d5e8bc653a52d6dccb56b500904368a09955a3fe914efad7cf18147ce
5
5
  SHA512:
6
- metadata.gz: e3d50e8368efa58acb323b0fde998d3006a00ca4f044f72f5cb04f2313c3340a7f7577710b3b3a034f9d58699583952bdb60e9eb4d5ecbef3319f01d6e4bf713
7
- data.tar.gz: ebb4d26b60a9f6d2744cd184dce52c13551773d706319bb53c6566001b39312d87f6c7c98f0ee5b15bda856447a2516f8f2336e6eb7437db8898776e1ac6dc9d
6
+ metadata.gz: 378ad3d1c7acb1118491dc2896f9983119197f888a8cf610998734cb48495dc2651d4cbb217eee46b10958cc9417cb06db790ca3a8ff52b5dcf9b6ba99fc24ce
7
+ data.tar.gz: a7461765f075d468e2cc4cd8b237c82c3a0a140739bcec81ca452b9d5c633af4c8e7bf21acd099a4d713a20afbaf4ca7468868a16ca1d167939054b903ceca9b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Release History
2
2
 
3
+ ### 1.17.3 (2026-07-27)
4
+
5
+ #### Bug Fixes
6
+
7
+ * Add option validation and error handling to ServiceAccountCredentials.make_creds ([#588](https://github.com/googleapis/google-auth-library-ruby/issues/588)) ([3da9927](https://github.com/googleapis/google-auth-library-ruby/commit/3da9927091e3ffc4f2d062a404d837de962a6f97)), refs [#482](https://github.com/googleapis/google-auth-library-ruby/issues/482) [#544](https://github.com/googleapis/google-auth-library-ruby/issues/544)
8
+
3
9
  ### 1.17.2 (2026-07-23)
4
10
 
5
11
  #### Bug Fixes
@@ -45,6 +45,19 @@ module Google
45
45
  # @type [::String] The type name for this credential.
46
46
  CREDENTIAL_TYPE_NAME = "service_account".freeze
47
47
 
48
+ # @private
49
+ # @type [Array<Symbol>] Allowed option keys for make_creds.
50
+ VALID_MAKE_CREDS_OPTIONS = [
51
+ :json_key_io,
52
+ :scope,
53
+ :enable_self_signed_jwt,
54
+ :target_audience,
55
+ :audience,
56
+ :token_credential_uri,
57
+ :default_connection,
58
+ :connection_builder
59
+ ].freeze
60
+
48
61
  def enable_self_signed_jwt?
49
62
  # Use a self-singed JWT if there's no information that can be used to
50
63
  # obtain an OAuth token, OR if there are scopes but also an assertion
@@ -55,10 +68,20 @@ module Google
55
68
 
56
69
  # Creates a ServiceAccountCredentials.
57
70
  #
58
- # @param json_key_io [IO] An IO object containing the JSON key
59
- # @param scope [string|array|nil] the scope(s) to access
71
+ # @param json_key_io [IO, nil] Optional. An IO object containing the JSON key
72
+ # @param scope [String, Array<String>, nil] Optional. The scope(s) to access
73
+ # @param enable_self_signed_jwt [Boolean, nil] Optional. Whether to use self-signed JWTs
74
+ # @param target_audience [String, nil] Optional. The target audience for ID token requests
75
+ # @param audience [String, nil] Optional. Custom token endpoint audience URI
76
+ # @param token_credential_uri [String, nil] Optional. Custom token credential URI
77
+ # @param default_connection [Faraday::Connection, nil] Optional. The connection object to use
78
+ # @param connection_builder [Proc, nil] Optional. A Proc that returns a Faraday connection
60
79
  # @raise [ArgumentError] If both scope and target_audience are specified
80
+ # @raise [InitializationError] If json_key_io is not an IO object, or
81
+ # if required credential fields (private_key or client_email) are missing
61
82
  def self.make_creds options = {} # rubocop:disable Metrics/MethodLength
83
+ validate_make_creds_options options
84
+
62
85
  json_key_io, scope, enable_self_signed_jwt, target_audience, audience, token_credential_uri =
63
86
  options.values_at :json_key_io, :scope, :enable_self_signed_jwt, :target_audience,
64
87
  :audience, :token_credential_uri
@@ -66,6 +89,9 @@ module Google
66
89
 
67
90
  private_key, client_email, project_id, quota_project_id, universe_domain =
68
91
  if json_key_io
92
+ unless json_key_io.respond_to? :read
93
+ raise InitializationError, "Expected an IO object for json_key_io"
94
+ end
69
95
  json_key = JSON.parse json_key_io.read
70
96
  if json_key.key? "type"
71
97
  json_key_io.rewind
@@ -78,6 +104,10 @@ module Google
78
104
  else
79
105
  creds_from_env
80
106
  end
107
+
108
+ raise InitializationError, "Missing required field: private_key" unless private_key
109
+ raise InitializationError, "Missing required field: client_email" unless client_email
110
+
81
111
  project_id ||= CredentialsLoader.load_gcloud_project_id
82
112
 
83
113
  new(token_credential_uri: token_credential_uri || TOKEN_CRED_URI,
@@ -122,8 +152,9 @@ module Google
122
152
  # enclosing quotes.
123
153
  #
124
154
  # @param str [String] The string to unescape
125
- # @return [String] The unescaped string
155
+ # @return [String, nil] The unescaped string, or nil if input is nil
126
156
  def self.unescape str
157
+ return nil unless str
127
158
  str = str.gsub '\n', "\n"
128
159
  str = str[1..-2] if str.start_with?('"') && str.end_with?('"')
129
160
  str
@@ -212,7 +243,20 @@ module Google
212
243
  [private_key, client_email, project_id, nil, nil]
213
244
  end
214
245
 
215
- private_class_method :creds_from_env
246
+ # @private
247
+ # Validates options passed to make_creds and emits a warning for unrecognized keys.
248
+ #
249
+ # @param options [Hash] The options hash to validate.
250
+ def self.validate_make_creds_options options
251
+ return unless options.is_a? Hash
252
+
253
+ unknown_keys = options.keys - VALID_MAKE_CREDS_OPTIONS
254
+ return if unknown_keys.empty?
255
+
256
+ warn "Unrecognized option(s) for ServiceAccountCredentials.make_creds: #{unknown_keys.map(&:inspect).join ', '}"
257
+ end
258
+
259
+ private_class_method :creds_from_env, :validate_make_creds_options
216
260
  end
217
261
  end
218
262
  end
@@ -16,6 +16,6 @@ module Google
16
16
  # Module Auth provides classes that provide Google-specific authorization
17
17
  # used to access Google APIs.
18
18
  module Auth
19
- VERSION = "1.17.2".freeze
19
+ VERSION = "1.17.3".freeze
20
20
  end
21
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googleauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.2
4
+ version: 1.17.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google LLC