googleauth-extras 0.5.0 → 0.6.0

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: 5ef5e7a09636bad627874135bfa0c1f020eace2016a31aaf8952a70b01465593
4
- data.tar.gz: 77d1fd18df712dbf3dd6620c4d3e2dfdcd0ced4872e6ebea6f05340cc8bf28f3
3
+ metadata.gz: 29022ef0b3431bad2d9e5833e3af8a5333307a60610b176d92e571d5aee59aeb
4
+ data.tar.gz: ce7ee1a8121b2b6781879bef17908190575fb3f3d0ce7e7eda8023d3a29a3463
5
5
  SHA512:
6
- metadata.gz: 9dbab8990a50ddcea8df7e25aa651c294005bf9827c2b3729d77dc07df601384ece65af0acec8eeda7337a9c0fc358f8b9540e3fdde074cd718a496994bd26b9
7
- data.tar.gz: 0e7aed934ce2b0e42f7e96e48ceca7866c81216e67a97b3e59f4027c298040c603e2c3a01e601914e8b33a97fb7c7457d52b70412a66f0bb2446b8a390cb8607
6
+ metadata.gz: 3cc8272a821cd99f51d2cc4de7f9979c42078aad8ddcaeafbec4523987aeebacd77947c86758851b6e1cfb18b13c6393cdffefe27dd629ae7c587c993f22e8cb
7
+ data.tar.gz: 3c6a26d85df2064d473f8ec8847f638a669ece26aeff38d7ad6f5ee918b5746da7882afd3331f3bb4686cafc88c3b2d5f38742008caa3df7c40992b9cc133b20
data/.rubocop.yml CHANGED
@@ -25,6 +25,9 @@ Metrics/CyclomaticComplexity:
25
25
  Metrics/MethodLength:
26
26
  Max: 30
27
27
 
28
+ Metrics/ModuleLength:
29
+ Max: 125
30
+
28
31
  Metrics/ParameterLists:
29
32
  Enabled: false
30
33
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Release History
2
2
 
3
+ 0.6.0
4
+ ----------
5
+
6
+ - Support setting the universe domain (defaults to googleapis.com) so gRPC google-cloud clients don't raise Gapic::UniverseDomainMismatch.
7
+ - drop `addressable` as a transitive dependency, replace with stdlib `uri`.
8
+ - drop `faraday` as a transitive dependency, replace with stdlib `net-http`.
9
+ - Bump minimum supported `googleauth` version which allows removing the identity credentials refresh patch (which has been fixed upstream).
10
+ - Clamp supported `signet` to `< 1` instead (no API regressions expected).
11
+
3
12
  0.5.0
4
13
  ----------
5
14
 
@@ -30,9 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ['lib']
32
32
 
33
- spec.add_dependency 'addressable', '~> 2.8'
34
- spec.add_dependency 'faraday', '>= 1.0', '< 3.0'
35
33
  spec.add_dependency 'google-apis-iamcredentials_v1'
36
- spec.add_dependency 'googleauth', '~> 1.3'
37
- spec.add_dependency 'signet', '>= 0.17.0', '< 0.19.0'
34
+ spec.add_dependency 'googleauth', '~> 1.11', '>= 1.11.1'
35
+ spec.add_dependency 'signet', '>= 0.17.0', '< 1'
38
36
  end
@@ -5,8 +5,6 @@ module Google
5
5
  module Extras
6
6
  # This credential impersonates a service account.
7
7
  class ImpersonatedCredential < Signet::OAuth2::Client
8
- include IdentityCredentialRefreshPatch
9
-
10
8
  attr_reader :quota_project_id
11
9
 
12
10
  # A credential that impersonates a service account.
@@ -49,6 +47,10 @@ module Google
49
47
  # @param target_audience [String]
50
48
  # The audience for the token, such as the API or account that this token grants access to.
51
49
  #
50
+ # @param universe_domain [String]
51
+ # The universe domain of the credential, reported to gRPC google-cloud clients so they
52
+ # don't raise Gapic::UniverseDomainMismatch. Defaults to googleapis.com.
53
+ #
52
54
  # @see https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/generateAccessToken
53
55
  # @see https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/generateIdToken
54
56
  # @see https://cloud.google.com/iam/docs/create-short-lived-credentials-delegated#sa-credentials-permissions
@@ -62,9 +64,15 @@ module Google
62
64
  lifetime: nil,
63
65
  quota_project_id: nil,
64
66
  scope: nil,
65
- target_audience: nil
67
+ target_audience: nil,
68
+ universe_domain: 'googleapis.com'
66
69
  )
67
- super(client_id: target_audience, scope: scope, target_audience: target_audience)
70
+ super(
71
+ client_id: target_audience,
72
+ scope: scope,
73
+ target_audience: target_audience,
74
+ universe_domain: base_credentials&.universe_domain || universe_domain,
75
+ )
68
76
 
69
77
  if self.target_audience.nil? || self.target_audience.empty?
70
78
  raise(ArgumentError, 'Must provide scope or target_audience') if self.scope.nil? || self.scope.empty?
@@ -5,8 +5,6 @@ module Google
5
5
  module Extras
6
6
  # This credential issues JWTs signed a service account.
7
7
  class ServiceAccountJWTCredential < Signet::OAuth2::Client
8
- include IdentityCredentialRefreshPatch
9
-
10
8
  # A credential that obtains a signed JWT from Google for a service account.
11
9
  #
12
10
  # @param base_credentials [Hash, String, Signet::OAuth2::Client]
@@ -34,6 +32,10 @@ module Google
34
32
  # @param target_audience [String]
35
33
  # The audience for the token, such as the API or account that this token grants access to.
36
34
  #
35
+ # @param universe_domain [String]
36
+ # The universe domain of the credential, reported to gRPC google-cloud clients so they
37
+ # don't raise Gapic::UniverseDomainMismatch. Defaults to googleapis.com.
38
+ #
37
39
  # @see https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signJwt
38
40
  # @see https://cloud.google.com/iam/docs/create-short-lived-credentials-delegated#sa-credentials-permissions
39
41
  #
@@ -44,9 +46,14 @@ module Google
44
46
  delegate_email_addresses: nil,
45
47
  issuer: nil,
46
48
  lifetime: 3600,
47
- subject: nil
49
+ subject: nil,
50
+ universe_domain: 'googleapis.com'
48
51
  )
49
- super(client_id: target_audience, target_audience: target_audience)
52
+ super(
53
+ client_id: target_audience,
54
+ target_audience: target_audience,
55
+ universe_domain: base_credentials&.universe_domain || universe_domain,
56
+ )
50
57
 
51
58
  @iam_credentials_service = Google::Apis::IamcredentialsV1::IAMCredentialsService.new.tap do |ics|
52
59
  ics.authorization = base_credentials if base_credentials
@@ -18,11 +18,16 @@ module Google
18
18
  # The project ID used for quota and billing. This project may be different from
19
19
  # the project used to create the credentials.
20
20
  #
21
- def initialize(access_token:, quota_project_id: nil)
21
+ # @param universe_domain [String]
22
+ # The universe domain of the credential, reported to gRPC google-cloud clients so they
23
+ # don't raise Gapic::UniverseDomainMismatch. Defaults to googleapis.com.
24
+ #
25
+ def initialize(access_token:, quota_project_id: nil, universe_domain: 'googleapis.com')
22
26
  super(
23
27
  access_token: access_token,
24
28
  expires_at: TokenInfo.lookup_access_token(access_token).fetch('exp'),
25
29
  issued_at: nil,
30
+ universe_domain: universe_domain,
26
31
  )
27
32
 
28
33
  @quota_project_id = quota_project_id
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'uri'
4
+
3
5
  module Google
4
6
  module Auth
5
7
  module Extras
@@ -11,7 +13,7 @@ module Google
11
13
  class LookupFailed < StandardError; end
12
14
  class LookupMalformed < LookupFailed; end
13
15
 
14
- TOKEN_INFO_URI = 'https://oauth2.googleapis.com/tokeninfo'
16
+ TOKEN_INFO_URI = URI('https://oauth2.googleapis.com/tokeninfo')
15
17
  private_constant :TOKEN_INFO_URI
16
18
 
17
19
  # Lookup the details for a valid access token, including it's expiration.
@@ -30,14 +32,14 @@ module Google
30
32
  private
31
33
 
32
34
  def lookup(query)
33
- url = Addressable::URI.parse(TOKEN_INFO_URI)
34
- url.query_values = query
35
+ query_string = URI.encode_www_form(query)
36
+ uri = TOKEN_INFO_URI.merge("?#{query_string}")
35
37
 
36
- response = Faraday.default_connection.get(url.normalize.to_s)
38
+ response = Net::HTTP.get_response(uri)
37
39
 
38
- raise LookupFailed, response.body.to_s unless response.status == 200
40
+ raise LookupFailed, response.body unless response.is_a?(Net::HTTPSuccess)
39
41
 
40
- credentials = Signet::OAuth2.parse_credentials(response.body, response.headers['Content-Type'])
42
+ credentials = Signet::OAuth2.parse_credentials(response.body, response['Content-Type'])
41
43
 
42
44
  raise LookupMalformed, 'Missing token expiry' unless credentials['exp']
43
45
 
@@ -3,7 +3,7 @@
3
3
  module Google
4
4
  module Auth
5
5
  module Extras
6
- VERSION = '0.5.0'
6
+ VERSION = '0.6.0'
7
7
  end
8
8
  end
9
9
  end
@@ -4,7 +4,6 @@ require 'date'
4
4
  require 'google/apis/iamcredentials_v1'
5
5
  require 'signet/oauth_2/client'
6
6
 
7
- require 'google/auth/extras/identity_credential_refresh_patch'
8
7
  require 'google/auth/extras/impersonated_credential'
9
8
  require 'google/auth/extras/service_account_jwt_credential'
10
9
  require 'google/auth/extras/static_credential'
@@ -59,6 +58,10 @@ module Google
59
58
  # The OAuth 2 scopes to request. Can either be formatted as a comma seperated string or array.
60
59
  # Only supported when not using a target_audience.
61
60
  #
61
+ # @param universe_domain [String]
62
+ # The universe domain of the credential, reported to gRPC google-cloud clients so they
63
+ # don't raise Gapic::UniverseDomainMismatch. Defaults to googleapis.com.
64
+ #
62
65
  # @return [Google::Auth::Extras::ImpersonatedCredential]
63
66
  #
64
67
  # @see https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/generateAccessToken
@@ -74,7 +77,8 @@ module Google
74
77
  lifetime: nil,
75
78
  quota_project_id: nil,
76
79
  scope: nil,
77
- target_audience: nil
80
+ target_audience: nil,
81
+ universe_domain: 'googleapis.com'
78
82
  )
79
83
  ImpersonatedCredential.new(
80
84
  base_credentials: base_credentials,
@@ -85,6 +89,7 @@ module Google
85
89
  quota_project_id: quota_project_id,
86
90
  scope: scope,
87
91
  target_audience: target_audience,
92
+ universe_domain: universe_domain,
88
93
  )
89
94
  end
90
95
 
@@ -121,6 +126,10 @@ module Google
121
126
  # The OAuth 2 scopes to request. Can either be formatted as a comma seperated string or array.
122
127
  # Only supported when not using a target_audience.
123
128
  #
129
+ # @param universe_domain [String]
130
+ # The universe domain of the credential, reported to gRPC google-cloud clients so they
131
+ # don't raise Gapic::UniverseDomainMismatch. Defaults to googleapis.com.
132
+ #
124
133
  # @return [Google::Auth::Credential<Google::Auth::Extras::ImpersonatedCredential>]
125
134
  #
126
135
  # @see https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/generateAccessToken
@@ -136,7 +145,8 @@ module Google
136
145
  lifetime: nil,
137
146
  quota_project_id: nil,
138
147
  scope: nil,
139
- target_audience: nil
148
+ target_audience: nil,
149
+ universe_domain: 'googleapis.com'
140
150
  )
141
151
  wrap_authorization(
142
152
  impersonated_authorization(
@@ -148,6 +158,7 @@ module Google
148
158
  quota_project_id: quota_project_id,
149
159
  scope: scope,
150
160
  target_audience: target_audience,
161
+ universe_domain: universe_domain,
151
162
  ),
152
163
  )
153
164
  end
@@ -182,6 +193,10 @@ module Google
182
193
  # @param target_audience [String]
183
194
  # The audience for the token, such as the API or account that this token grants access to.
184
195
  #
196
+ # @param universe_domain [String]
197
+ # The universe domain of the credential, reported to gRPC google-cloud clients so they
198
+ # don't raise Gapic::UniverseDomainMismatch. Defaults to googleapis.com.
199
+ #
185
200
  # @return [Google::Auth::Extras::ServiceAccountJWTCredential]
186
201
  #
187
202
  # @see https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signJwt
@@ -194,7 +209,8 @@ module Google
194
209
  delegate_email_addresses: nil,
195
210
  issuer: nil,
196
211
  lifetime: 3600,
197
- subject: nil
212
+ subject: nil,
213
+ universe_domain: 'googleapis.com'
198
214
  )
199
215
  ServiceAccountJWTCredential.new(
200
216
  base_credentials: base_credentials,
@@ -204,6 +220,7 @@ module Google
204
220
  lifetime: lifetime,
205
221
  subject: subject,
206
222
  target_audience: target_audience,
223
+ universe_domain: universe_domain,
207
224
  )
208
225
  end
209
226
 
@@ -235,6 +252,10 @@ module Google
235
252
  # @param target_audience [String]
236
253
  # The audience for the token, such as the API or account that this token grants access to.
237
254
  #
255
+ # @param universe_domain [String]
256
+ # The universe domain of the credential, reported to gRPC google-cloud clients so they
257
+ # don't raise Gapic::UniverseDomainMismatch. Defaults to googleapis.com.
258
+ #
238
259
  # @return [Google::Auth::Extras::ServiceAccountJWTCredential]
239
260
  #
240
261
  # @see https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signJwt
@@ -247,7 +268,8 @@ module Google
247
268
  delegate_email_addresses: nil,
248
269
  issuer: nil,
249
270
  lifetime: 3600,
250
- subject: nil
271
+ subject: nil,
272
+ universe_domain: 'googleapis.com'
251
273
  )
252
274
  wrap_authorization(
253
275
  service_account_jwt_authorization(
@@ -258,6 +280,7 @@ module Google
258
280
  lifetime: lifetime,
259
281
  subject: subject,
260
282
  target_audience: target_audience,
283
+ universe_domain: universe_domain,
261
284
  ),
262
285
  )
263
286
  end
@@ -272,11 +295,14 @@ module Google
272
295
  # The project ID used for quota and billing. This project may be different from
273
296
  # the project used to create the credentials.
274
297
  #
298
+ # @param universe_domain [String]
299
+ # The universe domain of the credential, reported to gRPC google-cloud clients so they
300
+ # don't raise Gapic::UniverseDomainMismatch. Defaults to googleapis.com.
275
301
  #
276
302
  # @return [Google::Auth::Extras::StaticCredential]
277
303
  #
278
- def static_authorization(token, quota_project_id: nil)
279
- StaticCredential.new(access_token: token, quota_project_id: quota_project_id)
304
+ def static_authorization(token, quota_project_id: nil, universe_domain: 'googleapis.com')
305
+ StaticCredential.new(access_token: token, quota_project_id: quota_project_id, universe_domain: universe_domain)
280
306
  end
281
307
 
282
308
  # A credential using a static access token. For usage with the newer
@@ -289,17 +315,25 @@ module Google
289
315
  # The project ID used for quota and billing. This project may be different from
290
316
  # the project used to create the credentials.
291
317
  #
318
+ # @param universe_domain [String]
319
+ # The universe domain of the credential, reported to gRPC google-cloud clients so they
320
+ # don't raise Gapic::UniverseDomainMismatch. Defaults to googleapis.com.
321
+ #
292
322
  # @return [Google::Auth::Credential<Google::Auth::Extras::StaticCredential>]
293
323
  #
294
- def static_credential(token, quota_project_id: nil)
295
- wrap_authorization(static_authorization(token, quota_project_id: quota_project_id))
324
+ def static_credential(token, quota_project_id: nil, universe_domain: 'googleapis.com')
325
+ wrap_authorization(
326
+ static_authorization(token, quota_project_id: quota_project_id, universe_domain: universe_domain),
327
+ )
296
328
  end
297
329
 
298
330
  # Take an authorization and turn it into a credential, primarily used
299
331
  # for setting up both the old and new style SDKs.
300
332
  #
301
333
  # @param client [Signet::OAuth2::Client]
302
- # Authorization credential to wrap.
334
+ # Authorization credential to wrap. The universe domain reported to gRPC google-cloud
335
+ # clients (so they don't raise Gapic::UniverseDomainMismatch) is taken from the client
336
+ # as-is; set it on the client before wrapping if needed.
303
337
  #
304
338
  # @return [Google::Auth::Credential]
305
339
  #
metadata CHANGED
@@ -1,49 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googleauth-extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Persona Identities
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-16 00:00:00.000000000 Z
11
+ date: 2026-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: addressable
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.8'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '2.8'
27
- - !ruby/object:Gem::Dependency
28
- name: faraday
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '1.0'
34
- - - "<"
35
- - !ruby/object:Gem::Version
36
- version: '3.0'
37
- type: :runtime
38
- prerelease: false
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: '1.0'
44
- - - "<"
45
- - !ruby/object:Gem::Version
46
- version: '3.0'
47
13
  - !ruby/object:Gem::Dependency
48
14
  name: google-apis-iamcredentials_v1
49
15
  requirement: !ruby/object:Gem::Requirement
@@ -64,14 +30,20 @@ dependencies:
64
30
  requirements:
65
31
  - - "~>"
66
32
  - !ruby/object:Gem::Version
67
- version: '1.3'
33
+ version: '1.11'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 1.11.1
68
37
  type: :runtime
69
38
  prerelease: false
70
39
  version_requirements: !ruby/object:Gem::Requirement
71
40
  requirements:
72
41
  - - "~>"
73
42
  - !ruby/object:Gem::Version
74
- version: '1.3'
43
+ version: '1.11'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.11.1
75
47
  - !ruby/object:Gem::Dependency
76
48
  name: signet
77
49
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +53,7 @@ dependencies:
81
53
  version: 0.17.0
82
54
  - - "<"
83
55
  - !ruby/object:Gem::Version
84
- version: 0.19.0
56
+ version: '1'
85
57
  type: :runtime
86
58
  prerelease: false
87
59
  version_requirements: !ruby/object:Gem::Requirement
@@ -91,7 +63,7 @@ dependencies:
91
63
  version: 0.17.0
92
64
  - - "<"
93
65
  - !ruby/object:Gem::Version
94
- version: 0.19.0
66
+ version: '1'
95
67
  description:
96
68
  email:
97
69
  - alex.coomans@withpersona.com
@@ -113,7 +85,6 @@ files:
113
85
  - bin/setup
114
86
  - googleauth-extras.gemspec
115
87
  - lib/google/auth/extras.rb
116
- - lib/google/auth/extras/identity_credential_refresh_patch.rb
117
88
  - lib/google/auth/extras/impersonated_credential.rb
118
89
  - lib/google/auth/extras/service_account_jwt_credential.rb
119
90
  - lib/google/auth/extras/static_credential.rb
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Google
4
- module Auth
5
- module Extras
6
- # This module fixes an issue with ID tokens not automatically refreshing
7
- # because their expiration is encoded in the JWT.
8
- module IdentityCredentialRefreshPatch
9
- def update_token!(*)
10
- super.tap do
11
- self.expires_at = decoded_id_token['exp'] if id_token
12
- end
13
- end
14
- end
15
- end
16
- end
17
- end