googleauth 1.8.0 → 1.15.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 +4 -4
- data/CHANGELOG.md +117 -0
- data/Credentials.md +106 -0
- data/Errors.md +152 -0
- data/README.md +49 -1
- data/lib/googleauth/api_key.rb +164 -0
- data/lib/googleauth/application_default.rb +6 -8
- data/lib/googleauth/base_client.rb +21 -4
- data/lib/googleauth/bearer_token.rb +162 -0
- data/lib/googleauth/client_id.rb +9 -6
- data/lib/googleauth/compute_engine.rb +231 -49
- data/lib/googleauth/credentials.rb +187 -58
- data/lib/googleauth/credentials_loader.rb +11 -20
- data/lib/googleauth/default_credentials.rb +29 -8
- data/lib/googleauth/errors.rb +117 -0
- data/lib/googleauth/external_account/aws_credentials.rb +85 -18
- data/lib/googleauth/external_account/base_credentials.rb +67 -6
- data/lib/googleauth/external_account/external_account_utils.rb +15 -4
- data/lib/googleauth/external_account/identity_pool_credentials.rb +40 -15
- data/lib/googleauth/external_account/pluggable_credentials.rb +34 -19
- data/lib/googleauth/external_account.rb +32 -7
- data/lib/googleauth/helpers/connection.rb +7 -1
- data/lib/googleauth/iam.rb +19 -3
- data/lib/googleauth/id_tokens/errors.rb +13 -7
- data/lib/googleauth/id_tokens/key_sources.rb +13 -7
- data/lib/googleauth/id_tokens/verifier.rb +2 -3
- data/lib/googleauth/id_tokens.rb +4 -6
- data/lib/googleauth/impersonated_service_account.rb +329 -0
- data/lib/googleauth/json_key_reader.rb +13 -3
- data/lib/googleauth/oauth2/sts_client.rb +9 -4
- data/lib/googleauth/scope_util.rb +1 -1
- data/lib/googleauth/service_account.rb +84 -104
- data/lib/googleauth/service_account_jwt_header.rb +187 -0
- data/lib/googleauth/signet.rb +169 -4
- data/lib/googleauth/token_store.rb +3 -3
- data/lib/googleauth/user_authorizer.rb +89 -11
- data/lib/googleauth/user_refresh.rb +72 -9
- data/lib/googleauth/version.rb +1 -1
- data/lib/googleauth/web_user_authorizer.rb +65 -17
- data/lib/googleauth.rb +8 -0
- metadata +45 -13
@@ -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
|
@@ -93,11 +96,22 @@ module Google
|
|
93
96
|
# Authorization scope to request
|
94
97
|
# @param [Google::Auth::Stores::TokenStore] token_store
|
95
98
|
# Backing storage for persisting user credentials
|
96
|
-
# @param [String]
|
99
|
+
# @param [String] legacy_callback_uri
|
97
100
|
# URL (either absolute or relative) of the auth callback. Defaults
|
98
|
-
# to '/oauth2callback'
|
99
|
-
|
100
|
-
|
101
|
+
# to '/oauth2callback'.
|
102
|
+
# @deprecated This field is deprecated. Instead, use the keyword
|
103
|
+
# argument callback_uri.
|
104
|
+
# @param [String] code_verifier
|
105
|
+
# Random string of 43-128 chars used to verify the key exchange using
|
106
|
+
# PKCE.
|
107
|
+
def initialize client_id, scope, token_store,
|
108
|
+
legacy_callback_uri = nil,
|
109
|
+
callback_uri: nil,
|
110
|
+
code_verifier: nil
|
111
|
+
super client_id, scope, token_store,
|
112
|
+
legacy_callback_uri,
|
113
|
+
code_verifier: code_verifier,
|
114
|
+
callback_uri: callback_uri
|
101
115
|
end
|
102
116
|
|
103
117
|
# Handle the result of the oauth callback. Exchanges the authorization
|
@@ -140,11 +154,13 @@ module Google
|
|
140
154
|
# Optional key-values to be returned to the oauth callback.
|
141
155
|
# @return [String]
|
142
156
|
# Authorization url
|
157
|
+
# @raise [Google::Auth::InitializationError]
|
158
|
+
# If request is nil or request.session is nil
|
143
159
|
def get_authorization_url options = {}
|
144
160
|
options = options.dup
|
145
161
|
request = options[:request]
|
146
|
-
raise NIL_REQUEST_ERROR if request.nil?
|
147
|
-
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?
|
148
164
|
|
149
165
|
state = options[:state] || {}
|
150
166
|
|
@@ -170,9 +186,9 @@ module Google
|
|
170
186
|
# requested scopes
|
171
187
|
# @return [Google::Auth::UserRefreshCredentials]
|
172
188
|
# Stored credentials, nil if none present
|
173
|
-
# @raise [
|
174
|
-
#
|
175
|
-
#
|
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
|
176
192
|
def get_credentials user_id, request = nil, scope = nil
|
177
193
|
if request&.session&.key? CALLBACK_STATE_KEY
|
178
194
|
# Note - in theory, no need to check required scope as this is
|
@@ -191,18 +207,33 @@ module Google
|
|
191
207
|
end
|
192
208
|
end
|
193
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
|
194
216
|
def self.extract_callback_state request
|
195
|
-
state = MultiJson.load(request[STATE_PARAM] || "{}")
|
217
|
+
state = MultiJson.load(request.params[STATE_PARAM] || "{}")
|
196
218
|
redirect_uri = state[CURRENT_URI_KEY]
|
197
219
|
callback_state = {
|
198
|
-
AUTH_CODE_KEY => request[AUTH_CODE_KEY],
|
199
|
-
ERROR_CODE_KEY => request[ERROR_CODE_KEY],
|
220
|
+
AUTH_CODE_KEY => request.params[AUTH_CODE_KEY],
|
221
|
+
ERROR_CODE_KEY => request.params[ERROR_CODE_KEY],
|
200
222
|
SESSION_ID_KEY => state[SESSION_ID_KEY],
|
201
|
-
SCOPE_KEY => request[SCOPE_KEY]
|
223
|
+
SCOPE_KEY => request.params[SCOPE_KEY]
|
202
224
|
}
|
203
225
|
[callback_state, redirect_uri]
|
204
226
|
end
|
205
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
|
+
|
206
237
|
# Verifies the results of an authorization callback
|
207
238
|
#
|
208
239
|
# @param [Hash] state
|
@@ -213,13 +244,30 @@ module Google
|
|
213
244
|
# Error message if failed
|
214
245
|
# @param [Rack::Request] request
|
215
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
|
216
250
|
def self.validate_callback_state state, request
|
217
|
-
|
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
|
+
|
218
259
|
if state[ERROR_CODE_KEY]
|
219
|
-
raise
|
220
|
-
|
260
|
+
raise AuthorizationError.with_details(
|
261
|
+
format(AUTHORIZATION_ERROR, state[ERROR_CODE_KEY]),
|
262
|
+
credential_type_name: name,
|
263
|
+
principal: principal
|
264
|
+
)
|
221
265
|
elsif request.session[XSRF_KEY] != state[SESSION_ID_KEY]
|
222
|
-
raise
|
266
|
+
raise AuthorizationError.with_details(
|
267
|
+
INVALID_STATE_TOKEN_ERROR,
|
268
|
+
credential_type_name: name,
|
269
|
+
principal: principal
|
270
|
+
)
|
223
271
|
end
|
224
272
|
end
|
225
273
|
|
data/lib/googleauth.rb
CHANGED
@@ -13,9 +13,17 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
require "googleauth/application_default"
|
16
|
+
require "googleauth/api_key"
|
17
|
+
require "googleauth/bearer_token"
|
16
18
|
require "googleauth/client_id"
|
17
19
|
require "googleauth/credentials"
|
18
20
|
require "googleauth/default_credentials"
|
21
|
+
require "googleauth/errors"
|
22
|
+
require "googleauth/external_account"
|
19
23
|
require "googleauth/id_tokens"
|
24
|
+
require "googleauth/impersonated_service_account"
|
25
|
+
require "googleauth/service_account"
|
26
|
+
require "googleauth/service_account_jwt_header"
|
20
27
|
require "googleauth/user_authorizer"
|
28
|
+
require "googleauth/user_refresh"
|
21
29
|
require "googleauth/web_user_authorizer"
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: googleauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- Google LLC
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: faraday
|
@@ -16,7 +15,7 @@ dependencies:
|
|
16
15
|
requirements:
|
17
16
|
- - ">="
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0
|
18
|
+
version: '1.0'
|
20
19
|
- - "<"
|
21
20
|
- !ruby/object:Gem::Version
|
22
21
|
version: 3.a
|
@@ -26,10 +25,38 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0
|
28
|
+
version: '1.0'
|
30
29
|
- - "<"
|
31
30
|
- !ruby/object:Gem::Version
|
32
31
|
version: 3.a
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: google-cloud-env
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - "~>"
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '2.2'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - "~>"
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.2'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: google-logging-utils
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0.1'
|
53
|
+
type: :runtime
|
54
|
+
prerelease: false
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0.1'
|
33
60
|
- !ruby/object:Gem::Dependency
|
34
61
|
name: jwt
|
35
62
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +66,7 @@ dependencies:
|
|
39
66
|
version: '1.4'
|
40
67
|
- - "<"
|
41
68
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
69
|
+
version: '4.0'
|
43
70
|
type: :runtime
|
44
71
|
prerelease: false
|
45
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,7 +76,7 @@ dependencies:
|
|
49
76
|
version: '1.4'
|
50
77
|
- - "<"
|
51
78
|
- !ruby/object:Gem::Version
|
52
|
-
version: '
|
79
|
+
version: '4.0'
|
53
80
|
- !ruby/object:Gem::Dependency
|
54
81
|
name: multi_json
|
55
82
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,7 +134,7 @@ dependencies:
|
|
107
134
|
description: Implements simple authorization for accessing Google APIs, and provides
|
108
135
|
support for Application Default Credentials.
|
109
136
|
email:
|
110
|
-
-
|
137
|
+
- googleapis-packages@google.com
|
111
138
|
executables: []
|
112
139
|
extensions: []
|
113
140
|
extra_rdoc_files: []
|
@@ -115,17 +142,22 @@ files:
|
|
115
142
|
- ".yardopts"
|
116
143
|
- CHANGELOG.md
|
117
144
|
- CODE_OF_CONDUCT.md
|
145
|
+
- Credentials.md
|
146
|
+
- Errors.md
|
118
147
|
- LICENSE
|
119
148
|
- README.md
|
120
149
|
- SECURITY.md
|
121
150
|
- lib/googleauth.rb
|
151
|
+
- lib/googleauth/api_key.rb
|
122
152
|
- lib/googleauth/application_default.rb
|
123
153
|
- lib/googleauth/base_client.rb
|
154
|
+
- lib/googleauth/bearer_token.rb
|
124
155
|
- lib/googleauth/client_id.rb
|
125
156
|
- lib/googleauth/compute_engine.rb
|
126
157
|
- lib/googleauth/credentials.rb
|
127
158
|
- lib/googleauth/credentials_loader.rb
|
128
159
|
- lib/googleauth/default_credentials.rb
|
160
|
+
- lib/googleauth/errors.rb
|
129
161
|
- lib/googleauth/external_account.rb
|
130
162
|
- lib/googleauth/external_account/aws_credentials.rb
|
131
163
|
- lib/googleauth/external_account/base_credentials.rb
|
@@ -138,10 +170,12 @@ files:
|
|
138
170
|
- lib/googleauth/id_tokens/errors.rb
|
139
171
|
- lib/googleauth/id_tokens/key_sources.rb
|
140
172
|
- lib/googleauth/id_tokens/verifier.rb
|
173
|
+
- lib/googleauth/impersonated_service_account.rb
|
141
174
|
- lib/googleauth/json_key_reader.rb
|
142
175
|
- lib/googleauth/oauth2/sts_client.rb
|
143
176
|
- lib/googleauth/scope_util.rb
|
144
177
|
- lib/googleauth/service_account.rb
|
178
|
+
- lib/googleauth/service_account_jwt_header.rb
|
145
179
|
- lib/googleauth/signet.rb
|
146
180
|
- lib/googleauth/stores/file_token_store.rb
|
147
181
|
- lib/googleauth/stores/redis_token_store.rb
|
@@ -157,7 +191,6 @@ metadata:
|
|
157
191
|
changelog_uri: https://github.com/googleapis/google-auth-library-ruby/blob/main/CHANGELOG.md
|
158
192
|
source_code_uri: https://github.com/googleapis/google-auth-library-ruby
|
159
193
|
bug_tracker_uri: https://github.com/googleapis/google-auth-library-ruby/issues
|
160
|
-
post_install_message:
|
161
194
|
rdoc_options: []
|
162
195
|
require_paths:
|
163
196
|
- lib
|
@@ -165,15 +198,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
198
|
requirements:
|
166
199
|
- - ">="
|
167
200
|
- !ruby/object:Gem::Version
|
168
|
-
version: '
|
201
|
+
version: '3.0'
|
169
202
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
203
|
requirements:
|
171
204
|
- - ">="
|
172
205
|
- !ruby/object:Gem::Version
|
173
206
|
version: '0'
|
174
207
|
requirements: []
|
175
|
-
rubygems_version: 3.
|
176
|
-
signing_key:
|
208
|
+
rubygems_version: 3.6.9
|
177
209
|
specification_version: 4
|
178
210
|
summary: Google Auth Library for Ruby
|
179
211
|
test_files: []
|