googleauth-extras 0.4.0 → 0.5.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: 29ad90b986d4915e183e4592f58eedff84badd6ee70900337981d3173f0c64b2
4
- data.tar.gz: 0c69256ea700526a9891d9434338954fec778d99b6f3c927654739dd690f03dd
3
+ metadata.gz: 5ef5e7a09636bad627874135bfa0c1f020eace2016a31aaf8952a70b01465593
4
+ data.tar.gz: 77d1fd18df712dbf3dd6620c4d3e2dfdcd0ced4872e6ebea6f05340cc8bf28f3
5
5
  SHA512:
6
- metadata.gz: 9b3de1122f1a208f337134b30023fef63eb171c5ad3c888a8cc0cb81bc72aa5ae0d476f1c22ff659d4ce4637795ffff5ae1a5e07eee64dd68f9a5f887e9f02bb
7
- data.tar.gz: 7eb79ba62b30a7b7a5cc2bab1d00f1079d19f57fd99df98ad52fec2d46d5e77eae781ddb50960c1832e77462e6b2e9d4c729e860db25610b2014432df6505f0d
6
+ metadata.gz: 9dbab8990a50ddcea8df7e25aa651c294005bf9827c2b3729d77dc07df601384ece65af0acec8eeda7337a9c0fc358f8b9540e3fdde074cd718a496994bd26b9
7
+ data.tar.gz: 0e7aed934ce2b0e42f7e96e48ceca7866c81216e67a97b3e59f4027c298040c603e2c3a01e601914e8b33a97fb7c7457d52b70412a66f0bb2446b8a390cb8607
@@ -14,10 +14,10 @@ jobs:
14
14
  fail-fast: false
15
15
  matrix:
16
16
  ruby:
17
- - '2.7'
18
- - '3.0'
19
17
  - '3.1'
20
18
  - '3.2'
19
+ - '3.3'
20
+ - '3.4'
21
21
  runs-on: ubuntu-latest
22
22
  steps:
23
23
  - uses: actions/checkout@v3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Release History
2
2
 
3
+ 0.5.0
4
+ ----------
5
+
6
+ - Support signed JWT credentials. ([#14](https://github.com/persona-id/googleauth-extras/pull/14))
7
+
8
+ - Drop support for Ruby 2.7 & 3.0, update test dependencies. ([#15](https://github.com/persona-id/googleauth-extras/pull/15))
9
+
3
10
  0.4.0
4
11
  ----------
5
12
 
data/Gemfile CHANGED
@@ -5,12 +5,12 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in googleauth-extras.gemspec
6
6
  gemspec
7
7
 
8
- gem 'google-cloud-storage', '~> 1.44'
8
+ gem 'google-cloud-storage', '~> 1.55'
9
9
 
10
- gem 'pry-byebug', '~> 3.10'
11
- gem 'rake', '~> 12.0'
12
- gem 'rspec', '~> 3.0'
13
- gem 'rubocop', '~> 1.45'
14
- gem 'rubocop-rspec', '~> 2.18'
15
- gem 'timecop', '~> 0.9.6'
16
- gem 'webmock', '~> 3.18'
10
+ gem 'pry-byebug', '~> 3.11'
11
+ gem 'rake', '~> 13.2'
12
+ gem 'rspec', '~> 3.13'
13
+ gem 'rubocop', '~> 1.75'
14
+ gem 'rubocop-rspec', '~> 3.5'
15
+ gem 'timecop', '~> 0.9.10'
16
+ gem 'webmock', '~> 3.25'
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.homepage = 'https://github.com/persona-id/googleauth-extras'
13
13
  spec.license = 'MIT'
14
14
 
15
- spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 3.1.0')
16
16
 
17
17
  spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
18
  spec.metadata['rubygems_mfa_required'] = 'true'
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Google
4
+ module Auth
5
+ module Extras
6
+ # This credential issues JWTs signed a service account.
7
+ class ServiceAccountJWTCredential < Signet::OAuth2::Client
8
+ include IdentityCredentialRefreshPatch
9
+
10
+ # A credential that obtains a signed JWT from Google for a service account.
11
+ #
12
+ # @param base_credentials [Hash, String, Signet::OAuth2::Client]
13
+ # Credentials to use to sign the JWTs.
14
+ #
15
+ # @param delegate_email_addresses [String, Array<String>]
16
+ # The email addresses (if any) of intermediate service accounts to reach
17
+ # the +email_address+ from +base_credentials+.
18
+ #
19
+ # @param email_address [String]
20
+ # Email of the service account to sign the JWT.
21
+ #
22
+ # @param issuer [String]
23
+ # The desired value of the iss field on the issued JWT. Defaults to the email_address.
24
+ #
25
+ # @param lifetime [Integers]
26
+ # The desired lifetime (in seconds) of the JWT before needing to be refreshed.
27
+ # Defaults to 3600 (1h), adjust as needed given a refresh is automatically
28
+ # performed when the token less than 60s of remaining life and refresh requires
29
+ # an additional API call.
30
+ #
31
+ # @param subject [String]
32
+ # The desired value of the sub field on the issued JWT. Defaults to the email_address.
33
+ #
34
+ # @param target_audience [String]
35
+ # The audience for the token, such as the API or account that this token grants access to.
36
+ #
37
+ # @see https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signJwt
38
+ # @see https://cloud.google.com/iam/docs/create-short-lived-credentials-delegated#sa-credentials-permissions
39
+ #
40
+ def initialize(
41
+ email_address:,
42
+ target_audience:,
43
+ base_credentials: nil,
44
+ delegate_email_addresses: nil,
45
+ issuer: nil,
46
+ lifetime: 3600,
47
+ subject: nil
48
+ )
49
+ super(client_id: target_audience, target_audience: target_audience)
50
+
51
+ @iam_credentials_service = Google::Apis::IamcredentialsV1::IAMCredentialsService.new.tap do |ics|
52
+ ics.authorization = base_credentials if base_credentials
53
+ end
54
+
55
+ @jwt_issuer = issuer || email_address
56
+ @jwt_lifetime = lifetime
57
+ @jwt_subject = subject || email_address
58
+
59
+ @sa_delegates = Array(delegate_email_addresses).map do |email|
60
+ transform_email_to_name(email)
61
+ end
62
+
63
+ @sa_name = transform_email_to_name(email_address)
64
+ end
65
+
66
+ def fetch_access_token(*)
67
+ now = Time.now.to_i
68
+
69
+ request = Google::Apis::IamcredentialsV1::SignJwtRequest.new(
70
+ payload: JSON.dump(
71
+ aud: target_audience,
72
+ exp: now + @jwt_lifetime,
73
+ iat: now,
74
+ iss: @jwt_issuer,
75
+ sub: @jwt_subject,
76
+ ),
77
+ )
78
+
79
+ # The Google SDK doesn't like nil repeated values, but be careful with others as well.
80
+ request.delegates = @sa_delegates unless @sa_delegates.empty?
81
+
82
+ response = @iam_credentials_service.sign_service_account_jwt(@sa_name, request)
83
+
84
+ {
85
+ id_token: response.signed_jwt,
86
+ }
87
+ end
88
+
89
+ def inspect
90
+ "#<#{self.class.name}" \
91
+ " @expires_at=#{expires_at.inspect}" \
92
+ " @id_token=#{@id_token ? '[REDACTED]' : 'nil'}" \
93
+ " @jwt_issuer=#{@jwt_issuer.inspect}" \
94
+ " @jwt_lifetime=#{@jwt_lifetime.inspect}" \
95
+ " @jwt_subject=#{@jwt_subject.inspect}" \
96
+ " @sa_delegates=#{@sa_delegates.inspect}" \
97
+ " @sa_name=#{@sa_name.inspect}" \
98
+ " @target_audience=#{@target_audience.inspect}" \
99
+ '>'
100
+ end
101
+
102
+ private
103
+
104
+ def transform_email_to_name(email)
105
+ "projects/-/serviceAccounts/#{email}"
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -3,7 +3,7 @@
3
3
  module Google
4
4
  module Auth
5
5
  module Extras
6
- VERSION = '0.4.0'
6
+ VERSION = '0.5.0'
7
7
  end
8
8
  end
9
9
  end
@@ -6,6 +6,7 @@ require 'signet/oauth_2/client'
6
6
 
7
7
  require 'google/auth/extras/identity_credential_refresh_patch'
8
8
  require 'google/auth/extras/impersonated_credential'
9
+ require 'google/auth/extras/service_account_jwt_credential'
9
10
  require 'google/auth/extras/static_credential'
10
11
  require 'google/auth/extras/token_info'
11
12
  require 'google/auth/extras/version'
@@ -151,6 +152,116 @@ module Google
151
152
  )
152
153
  end
153
154
 
155
+ # A credential that obtains a signed JWT from Google for a service account.
156
+ # For usage with the older style GCP Ruby SDKs from the google-apis-* gems.
157
+ # Also useful for calling IAP-protected endpoints using the Google-managed
158
+ # OAuth client.
159
+ #
160
+ # @param base_credentials [Hash, String, Signet::OAuth2::Client]
161
+ # Credentials to use to sign the JWTs.
162
+ #
163
+ # @param delegate_email_addresses [String, Array<String>]
164
+ # The email addresses (if any) of intermediate service accounts to reach
165
+ # the +email_address+ from +base_credentials+.
166
+ #
167
+ # @param email_address [String]
168
+ # Email of the service account to sign the JWT.
169
+ #
170
+ # @param issuer [String]
171
+ # The desired value of the iss field on the issued JWT. Defaults to the email_address.
172
+ #
173
+ # @param lifetime [Integers]
174
+ # The desired lifetime (in seconds) of the JWT before needing to be refreshed.
175
+ # Defaults to 3600 (1h), adjust as needed given a refresh is automatically
176
+ # performed when the token less than 60s of remaining life and refresh requires
177
+ # an additional API call.
178
+ #
179
+ # @param subject [String]
180
+ # The desired value of the sub field on the issued JWT. Defaults to the email_address.
181
+ #
182
+ # @param target_audience [String]
183
+ # The audience for the token, such as the API or account that this token grants access to.
184
+ #
185
+ # @return [Google::Auth::Extras::ServiceAccountJWTCredential]
186
+ #
187
+ # @see https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signJwt
188
+ # @see https://cloud.google.com/iam/docs/create-short-lived-credentials-delegated#sa-credentials-permissions
189
+ #
190
+ def service_account_jwt_authorization(
191
+ email_address:,
192
+ target_audience:,
193
+ base_credentials: nil,
194
+ delegate_email_addresses: nil,
195
+ issuer: nil,
196
+ lifetime: 3600,
197
+ subject: nil
198
+ )
199
+ ServiceAccountJWTCredential.new(
200
+ base_credentials: base_credentials,
201
+ delegate_email_addresses: delegate_email_addresses,
202
+ email_address: email_address,
203
+ issuer: issuer,
204
+ lifetime: lifetime,
205
+ subject: subject,
206
+ target_audience: target_audience,
207
+ )
208
+ end
209
+
210
+ # A credential that obtains a signed JWT from Google for a service account.
211
+ # For usage with the newer style GCP Ruby SDKs from the google-cloud-* gems.
212
+ #
213
+ # @param base_credentials [Hash, String, Signet::OAuth2::Client]
214
+ # Credentials to use to sign the JWTs.
215
+ #
216
+ # @param delegate_email_addresses [String, Array<String>]
217
+ # The email addresses (if any) of intermediate service accounts to reach
218
+ # the +email_address+ from +base_credentials+.
219
+ #
220
+ # @param email_address [String]
221
+ # Email of the service account to sign the JWT.
222
+ #
223
+ # @param issuer [String]
224
+ # The desired value of the iss field on the issued JWT. Defaults to the email_address.
225
+ #
226
+ # @param lifetime [Integers]
227
+ # The desired lifetime (in seconds) of the JWT before needing to be refreshed.
228
+ # Defaults to 3600 (1h), adjust as needed given a refresh is automatically
229
+ # performed when the token less than 60s of remaining life and refresh requires
230
+ # an additional API call.
231
+ #
232
+ # @param subject [String]
233
+ # The desired value of the sub field on the issued JWT. Defaults to the email_address.
234
+ #
235
+ # @param target_audience [String]
236
+ # The audience for the token, such as the API or account that this token grants access to.
237
+ #
238
+ # @return [Google::Auth::Extras::ServiceAccountJWTCredential]
239
+ #
240
+ # @see https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signJwt
241
+ # @see https://cloud.google.com/iam/docs/create-short-lived-credentials-delegated#sa-credentials-permissions
242
+ #
243
+ def service_account_jwt_credential(
244
+ email_address:,
245
+ target_audience:,
246
+ base_credentials: nil,
247
+ delegate_email_addresses: nil,
248
+ issuer: nil,
249
+ lifetime: 3600,
250
+ subject: nil
251
+ )
252
+ wrap_authorization(
253
+ service_account_jwt_authorization(
254
+ base_credentials: base_credentials,
255
+ delegate_email_addresses: delegate_email_addresses,
256
+ email_address: email_address,
257
+ issuer: issuer,
258
+ lifetime: lifetime,
259
+ subject: subject,
260
+ target_audience: target_audience,
261
+ ),
262
+ )
263
+ end
264
+
154
265
  # A credential using a static access token. For usage with the older
155
266
  # style GCP Ruby SDKs from the google-apis-* gems.
156
267
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googleauth-extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Persona Identities
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-06 00:00:00.000000000 Z
11
+ date: 2025-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -92,7 +92,7 @@ dependencies:
92
92
  - - "<"
93
93
  - !ruby/object:Gem::Version
94
94
  version: 0.19.0
95
- description:
95
+ description:
96
96
  email:
97
97
  - alex.coomans@withpersona.com
98
98
  executables: []
@@ -115,6 +115,7 @@ files:
115
115
  - lib/google/auth/extras.rb
116
116
  - lib/google/auth/extras/identity_credential_refresh_patch.rb
117
117
  - lib/google/auth/extras/impersonated_credential.rb
118
+ - lib/google/auth/extras/service_account_jwt_credential.rb
118
119
  - lib/google/auth/extras/static_credential.rb
119
120
  - lib/google/auth/extras/token_info.rb
120
121
  - lib/google/auth/extras/version.rb
@@ -128,7 +129,7 @@ metadata:
128
129
  homepage_uri: https://github.com/persona-id/googleauth-extras
129
130
  source_code_uri: https://github.com/persona-id/googleauth-extras
130
131
  changelog_uri: https://github.com/persona-id/googleauth-extras/blob/main/CHANGELOG.md
131
- post_install_message:
132
+ post_install_message:
132
133
  rdoc_options: []
133
134
  require_paths:
134
135
  - lib
@@ -136,15 +137,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
137
  requirements:
137
138
  - - ">="
138
139
  - !ruby/object:Gem::Version
139
- version: 2.7.0
140
+ version: 3.1.0
140
141
  required_rubygems_version: !ruby/object:Gem::Requirement
141
142
  requirements:
142
143
  - - ">="
143
144
  - !ruby/object:Gem::Version
144
145
  version: '0'
145
146
  requirements: []
146
- rubygems_version: 3.4.10
147
- signing_key:
147
+ rubygems_version: 3.3.27
148
+ signing_key:
148
149
  specification_version: 4
149
150
  summary: Additions to the googleauth gem for unsupported authentication schemes.
150
151
  test_files: []