googleauth 1.14.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 +15 -0
- data/Credentials.md +106 -0
- data/Errors.md +152 -0
- data/lib/googleauth/api_key.rb +9 -0
- data/lib/googleauth/application_default.rb +3 -1
- data/lib/googleauth/base_client.rb +5 -0
- data/lib/googleauth/bearer_token.rb +16 -2
- data/lib/googleauth/client_id.rb +9 -5
- data/lib/googleauth/compute_engine.rb +64 -18
- data/lib/googleauth/credentials.rb +23 -6
- data/lib/googleauth/credentials_loader.rb +9 -4
- data/lib/googleauth/default_credentials.rb +16 -4
- 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 +31 -2
- 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 +30 -6
- 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 -4
- data/lib/googleauth/impersonated_service_account.rb +64 -17
- data/lib/googleauth/json_key_reader.rb +11 -2
- data/lib/googleauth/oauth2/sts_client.rb +9 -4
- data/lib/googleauth/scope_util.rb +1 -1
- data/lib/googleauth/service_account.rb +12 -1
- data/lib/googleauth/service_account_jwt_header.rb +9 -2
- data/lib/googleauth/signet.rb +24 -6
- data/lib/googleauth/user_authorizer.rb +35 -7
- data/lib/googleauth/user_refresh.rb +25 -7
- data/lib/googleauth/version.rb +1 -1
- data/lib/googleauth/web_user_authorizer.rb +46 -9
- data/lib/googleauth.rb +1 -0
- metadata +8 -5
@@ -12,6 +12,8 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
require "googleauth/errors"
|
16
|
+
|
15
17
|
module Google
|
16
18
|
# Module Auth provides classes that provide Google-specific authorization
|
17
19
|
# used to access Google APIs.
|
@@ -19,10 +21,17 @@ module Google
|
|
19
21
|
# JsonKeyReader contains the behaviour used to read private key and
|
20
22
|
# client email fields from the service account
|
21
23
|
module JsonKeyReader
|
24
|
+
# Reads a JSON key from an IO object and extracts common fields.
|
25
|
+
#
|
26
|
+
# @param json_key_io [IO] An IO object containing the JSON key
|
27
|
+
# @return [Array(String, String, String, String, String)] An array containing:
|
28
|
+
# private_key, client_email, project_id, quota_project_id, and universe_domain
|
29
|
+
# @raise [Google::Auth::InitializationError] If client_email or private_key
|
30
|
+
# fields are missing from the JSON
|
22
31
|
def read_json_key json_key_io
|
23
32
|
json_key = MultiJson.load json_key_io.read
|
24
|
-
raise "missing client_email" unless json_key.key? "client_email"
|
25
|
-
raise "missing private_key" unless json_key.key? "private_key"
|
33
|
+
raise InitializationError, "missing client_email" unless json_key.key? "client_email"
|
34
|
+
raise InitializationError, "missing private_key" unless json_key.key? "private_key"
|
26
35
|
[
|
27
36
|
json_key["private_key"],
|
28
37
|
json_key["client_email"],
|
@@ -12,6 +12,7 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
require "googleauth/errors"
|
15
16
|
require "googleauth/helpers/connection"
|
16
17
|
|
17
18
|
module Google
|
@@ -36,10 +37,12 @@ module Google
|
|
36
37
|
|
37
38
|
# Create a new instance of the STSClient.
|
38
39
|
#
|
39
|
-
# @param [
|
40
|
-
#
|
40
|
+
# @param [Hash] options Configuration options
|
41
|
+
# @option options [String] :token_exchange_endpoint The token exchange endpoint
|
42
|
+
# @option options [Faraday::Connection] :connection The Faraday connection to use
|
43
|
+
# @raise [Google::Auth::InitializationError] If token_exchange_endpoint is nil
|
41
44
|
def initialize options = {}
|
42
|
-
raise "Token exchange endpoint can not be nil" if options[:token_exchange_endpoint].nil?
|
45
|
+
raise InitializationError, "Token exchange endpoint can not be nil" if options[:token_exchange_endpoint].nil?
|
43
46
|
self.default_connection = options[:connection]
|
44
47
|
@token_exchange_endpoint = options[:token_exchange_endpoint]
|
45
48
|
end
|
@@ -67,6 +70,8 @@ module Google
|
|
67
70
|
# The optional additional headers to pass to the token exchange endpoint.
|
68
71
|
#
|
69
72
|
# @return [Hash] A hash containing the token exchange response.
|
73
|
+
# @raise [ArgumentError] If required options are missing
|
74
|
+
# @raise [Google::Auth::AuthorizationError] If the token exchange request fails
|
70
75
|
def exchange_token options = {}
|
71
76
|
missing_required_opts = [:grant_type, :subject_token, :subject_token_type] - options.keys
|
72
77
|
unless missing_required_opts.empty?
|
@@ -81,7 +86,7 @@ module Google
|
|
81
86
|
response = connection.post @token_exchange_endpoint, URI.encode_www_form(request_body), headers
|
82
87
|
|
83
88
|
if response.status != 200
|
84
|
-
raise "Token exchange failed with status #{response.status}"
|
89
|
+
raise AuthorizationError, "Token exchange failed with status #{response.status}"
|
85
90
|
end
|
86
91
|
|
87
92
|
MultiJson.load response.body
|
@@ -57,7 +57,7 @@ module Google
|
|
57
57
|
#
|
58
58
|
# @param scope [String,Array<String>] Input scope(s)
|
59
59
|
# @return [Array<String>] Always an array of strings
|
60
|
-
# @raise ArgumentError If the input is not a string or array of strings
|
60
|
+
# @raise [ArgumentError] If the input is not a string or array of strings
|
61
61
|
#
|
62
62
|
def self.as_array scope
|
63
63
|
case scope
|
@@ -51,8 +51,9 @@ module Google
|
|
51
51
|
|
52
52
|
# Creates a ServiceAccountCredentials.
|
53
53
|
#
|
54
|
-
# @param json_key_io [IO]
|
54
|
+
# @param json_key_io [IO] An IO object containing the JSON key
|
55
55
|
# @param scope [string|array|nil] the scope(s) to access
|
56
|
+
# @raise [ArgumentError] If both scope and target_audience are specified
|
56
57
|
def self.make_creds options = {}
|
57
58
|
json_key_io, scope, enable_self_signed_jwt, target_audience, audience, token_credential_uri =
|
58
59
|
options.values_at :json_key_io, :scope, :enable_self_signed_jwt, :target_audience,
|
@@ -110,6 +111,9 @@ module Google
|
|
110
111
|
# Handles certain escape sequences that sometimes appear in input.
|
111
112
|
# Specifically, interprets the "\n" sequence for newline, and removes
|
112
113
|
# enclosing quotes.
|
114
|
+
#
|
115
|
+
# @param str [String] The string to unescape
|
116
|
+
# @return [String] The unescaped string
|
113
117
|
def self.unescape str
|
114
118
|
str = str.gsub '\n', "\n"
|
115
119
|
str = str[1..-2] if str.start_with?('"') && str.end_with?('"')
|
@@ -164,6 +168,13 @@ module Google
|
|
164
168
|
self
|
165
169
|
end
|
166
170
|
|
171
|
+
# Returns the client email as the principal for service account credentials
|
172
|
+
# @private
|
173
|
+
# @return [String] the email address of the service account
|
174
|
+
def principal
|
175
|
+
@issuer
|
176
|
+
end
|
177
|
+
|
167
178
|
private
|
168
179
|
|
169
180
|
def apply_self_signed_jwt! a_hash
|
@@ -47,7 +47,7 @@ module Google
|
|
47
47
|
|
48
48
|
# Create a ServiceAccountJwtHeaderCredentials.
|
49
49
|
#
|
50
|
-
# @param json_key_io [IO]
|
50
|
+
# @param json_key_io [IO] An IO object containing the JSON key
|
51
51
|
# @param scope [string|array|nil] the scope(s) to access
|
52
52
|
def self.make_creds options = {}
|
53
53
|
json_key_io, scope = options.values_at :json_key_io, :scope
|
@@ -56,7 +56,7 @@ module Google
|
|
56
56
|
|
57
57
|
# Initializes a ServiceAccountJwtHeaderCredentials.
|
58
58
|
#
|
59
|
-
# @param json_key_io [IO]
|
59
|
+
# @param json_key_io [IO] An IO object containing the JSON key
|
60
60
|
def initialize options = {}
|
61
61
|
json_key_io = options[:json_key_io]
|
62
62
|
if json_key_io
|
@@ -159,6 +159,13 @@ module Google
|
|
159
159
|
false
|
160
160
|
end
|
161
161
|
|
162
|
+
# Returns the client email as the principal for service account JWT header credentials
|
163
|
+
# @private
|
164
|
+
# @return [String] the email address of the service account
|
165
|
+
def principal
|
166
|
+
@issuer
|
167
|
+
end
|
168
|
+
|
162
169
|
private
|
163
170
|
|
164
171
|
def deep_hash_normalize old_hash
|
data/lib/googleauth/signet.rb
CHANGED
@@ -16,6 +16,7 @@ require "base64"
|
|
16
16
|
require "json"
|
17
17
|
require "signet/oauth_2/client"
|
18
18
|
require "googleauth/base_client"
|
19
|
+
require "googleauth/errors"
|
19
20
|
|
20
21
|
module Signet
|
21
22
|
# OAuth2 supports OAuth2 authentication.
|
@@ -109,17 +110,29 @@ module Signet
|
|
109
110
|
end
|
110
111
|
end
|
111
112
|
|
113
|
+
# rubocop:disable Metrics/MethodLength
|
114
|
+
|
115
|
+
# Retries the provided block with exponential backoff, handling and wrapping errors.
|
116
|
+
#
|
117
|
+
# @param [Integer] max_retry_count The maximum number of retries before giving up
|
118
|
+
# @yield The block to execute and potentially retry
|
119
|
+
# @return [Object] The result of the block if successful
|
120
|
+
# @raise [Google::Auth::AuthorizationError] If a Signet::AuthorizationError occurs or if retries are exhausted
|
121
|
+
# @raise [Google::Auth::ParseError] If a Signet::ParseError occurs during token parsing
|
112
122
|
def retry_with_error max_retry_count = 5
|
113
123
|
retry_count = 0
|
114
124
|
|
115
125
|
begin
|
116
126
|
yield.tap { |resp| log_response resp }
|
127
|
+
rescue Signet::AuthorizationError, Signet::ParseError => e
|
128
|
+
log_auth_error e
|
129
|
+
error_class = e.is_a?(Signet::ParseError) ? Google::Auth::ParseError : Google::Auth::AuthorizationError
|
130
|
+
raise error_class.with_details(
|
131
|
+
e.message,
|
132
|
+
credential_type_name: self.class.name,
|
133
|
+
principal: respond_to?(:principal) ? principal : :signet_client
|
134
|
+
)
|
117
135
|
rescue StandardError => e
|
118
|
-
if e.is_a?(Signet::AuthorizationError) || e.is_a?(Signet::ParseError)
|
119
|
-
log_auth_error e
|
120
|
-
raise e
|
121
|
-
end
|
122
|
-
|
123
136
|
if retry_count < max_retry_count
|
124
137
|
log_transient_error e
|
125
138
|
retry_count += 1
|
@@ -128,10 +141,15 @@ module Signet
|
|
128
141
|
else
|
129
142
|
log_retries_exhausted e
|
130
143
|
msg = "Unexpected error: #{e.inspect}"
|
131
|
-
raise
|
144
|
+
raise Google::Auth::AuthorizationError.with_details(
|
145
|
+
msg,
|
146
|
+
credential_type_name: self.class.name,
|
147
|
+
principal: respond_to?(:principal) ? principal : :signet_client
|
148
|
+
)
|
132
149
|
end
|
133
150
|
end
|
134
151
|
end
|
152
|
+
# rubocop:enable Metrics/MethodLength
|
135
153
|
|
136
154
|
# Creates a duplicate of these credentials
|
137
155
|
# without the Signet::OAuth2::Client-specific
|
@@ -63,12 +63,14 @@ module Google
|
|
63
63
|
# @param [String] code_verifier
|
64
64
|
# Random string of 43-128 chars used to verify the key exchange using
|
65
65
|
# PKCE.
|
66
|
+
# @raise [Google::Auth::InitializationError]
|
67
|
+
# If client_id is nil or scope is nil
|
66
68
|
def initialize client_id, scope, token_store,
|
67
69
|
legacy_callback_uri = nil,
|
68
70
|
callback_uri: nil,
|
69
71
|
code_verifier: nil
|
70
|
-
raise NIL_CLIENT_ID_ERROR if client_id.nil?
|
71
|
-
raise NIL_SCOPE_ERROR if scope.nil?
|
72
|
+
raise InitializationError, NIL_CLIENT_ID_ERROR if client_id.nil?
|
73
|
+
raise InitializationError, NIL_SCOPE_ERROR if scope.nil?
|
72
74
|
|
73
75
|
@client_id = client_id
|
74
76
|
@scope = Array(scope)
|
@@ -133,14 +135,19 @@ module Google
|
|
133
135
|
# the requested scopes
|
134
136
|
# @return [Google::Auth::UserRefreshCredentials]
|
135
137
|
# Stored credentials, nil if none present
|
138
|
+
# @raise [Google::Auth::CredentialsError]
|
139
|
+
# If the client ID in the stored token doesn't match the configured client ID
|
136
140
|
def get_credentials user_id, scope = nil
|
137
141
|
saved_token = stored_token user_id
|
138
142
|
return nil if saved_token.nil?
|
139
143
|
data = MultiJson.load saved_token
|
140
144
|
|
141
145
|
if data.fetch("client_id", @client_id.id) != @client_id.id
|
142
|
-
raise
|
143
|
-
|
146
|
+
raise CredentialsError.with_details(
|
147
|
+
format(MISMATCHED_CLIENT_ID_ERROR, data["client_id"], @client_id.id),
|
148
|
+
credential_type_name: self.class.name,
|
149
|
+
principal: principal
|
150
|
+
)
|
144
151
|
end
|
145
152
|
|
146
153
|
credentials = UserRefreshCredentials.new(
|
@@ -240,6 +247,8 @@ module Google
|
|
240
247
|
# Unique ID of the user for loading/storing credentials.
|
241
248
|
# @param [Google::Auth::UserRefreshCredentials] credentials
|
242
249
|
# Credentials to store.
|
250
|
+
# @return [Google::Auth::UserRefreshCredentials]
|
251
|
+
# The stored credentials
|
243
252
|
def store_credentials user_id, credentials
|
244
253
|
json = MultiJson.dump(
|
245
254
|
client_id: credentials.client_id,
|
@@ -269,6 +278,15 @@ module Google
|
|
269
278
|
SecureRandom.alphanumeric random_number
|
270
279
|
end
|
271
280
|
|
281
|
+
# Returns the principal identifier for this authorizer
|
282
|
+
# The client ID is used as the principal for user authorizers
|
283
|
+
#
|
284
|
+
# @private
|
285
|
+
# @return [String] The client ID associated with this authorizer
|
286
|
+
def principal
|
287
|
+
@client_id.id
|
288
|
+
end
|
289
|
+
|
272
290
|
private
|
273
291
|
|
274
292
|
# @private Fetch stored token with given user_id
|
@@ -276,9 +294,11 @@ module Google
|
|
276
294
|
# @param [String] user_id
|
277
295
|
# Unique ID of the user for loading/storing credentials.
|
278
296
|
# @return [String] The saved token from @token_store
|
297
|
+
# @raise [Google::Auth::InitializationError]
|
298
|
+
# If user_id is nil or token_store is nil
|
279
299
|
def stored_token user_id
|
280
|
-
raise NIL_USER_ID_ERROR if user_id.nil?
|
281
|
-
raise NIL_TOKEN_STORE_ERROR if @token_store.nil?
|
300
|
+
raise InitializationError, NIL_USER_ID_ERROR if user_id.nil?
|
301
|
+
raise InitializationError, NIL_TOKEN_STORE_ERROR if @token_store.nil?
|
282
302
|
|
283
303
|
@token_store.load user_id
|
284
304
|
end
|
@@ -303,9 +323,17 @@ module Google
|
|
303
323
|
# Absolute URL to resolve the callback against if necessary.
|
304
324
|
# @return [String]
|
305
325
|
# Redirect URI
|
326
|
+
# @raise [Google::Auth::CredentialsError]
|
327
|
+
# If the callback URI is relative and base_url is nil or not absolute
|
306
328
|
def redirect_uri_for base_url
|
307
329
|
return @callback_uri if uri_is_postmessage?(@callback_uri) || !URI(@callback_uri).scheme.nil?
|
308
|
-
|
330
|
+
if base_url.nil? || URI(base_url).scheme.nil?
|
331
|
+
raise CredentialsError.with_details(
|
332
|
+
format(MISSING_ABSOLUTE_URL_ERROR, @callback_uri),
|
333
|
+
credential_type_name: self.class.name,
|
334
|
+
principal: principal
|
335
|
+
)
|
336
|
+
end
|
309
337
|
URI.join(base_url, @callback_uri).to_s
|
310
338
|
end
|
311
339
|
|
@@ -12,9 +12,10 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require "googleauth/signet"
|
16
15
|
require "googleauth/credentials_loader"
|
16
|
+
require "googleauth/errors"
|
17
17
|
require "googleauth/scope_util"
|
18
|
+
require "googleauth/signet"
|
18
19
|
require "multi_json"
|
19
20
|
|
20
21
|
module Google
|
@@ -40,7 +41,7 @@ module Google
|
|
40
41
|
|
41
42
|
# Create a UserRefreshCredentials.
|
42
43
|
#
|
43
|
-
# @param json_key_io [IO]
|
44
|
+
# @param json_key_io [IO] An IO object containing the JSON key
|
44
45
|
# @param scope [string|array|nil] the scope(s) to access
|
45
46
|
def self.make_creds options = {}
|
46
47
|
json_key_io, scope = options.values_at :json_key_io, :scope
|
@@ -64,13 +65,16 @@ module Google
|
|
64
65
|
.configure_connection(options)
|
65
66
|
end
|
66
67
|
|
67
|
-
# Reads
|
68
|
-
#
|
68
|
+
# Reads a JSON key from an IO object and extracts required fields.
|
69
|
+
#
|
70
|
+
# @param [IO] json_key_io An IO object containing the JSON key
|
71
|
+
# @return [Hash] The parsed JSON key
|
72
|
+
# @raise [Google::Auth::InitializationError] If the JSON is missing required fields
|
69
73
|
def self.read_json_key json_key_io
|
70
74
|
json_key = MultiJson.load json_key_io.read
|
71
75
|
wanted = ["client_id", "client_secret", "refresh_token"]
|
72
76
|
wanted.each do |key|
|
73
|
-
raise "the json is missing the #{key} field" unless json_key.key? key
|
77
|
+
raise InitializationError, "the json is missing the #{key} field" unless json_key.key? key
|
74
78
|
end
|
75
79
|
json_key
|
76
80
|
end
|
@@ -106,6 +110,10 @@ module Google
|
|
106
110
|
end
|
107
111
|
|
108
112
|
# Revokes the credential
|
113
|
+
#
|
114
|
+
# @param [Hash] options Options for revoking the credential
|
115
|
+
# @option options [Faraday::Connection] :connection The connection to use
|
116
|
+
# @raise [Google::Auth::AuthorizationError] If the revocation request fails
|
109
117
|
def revoke! options = {}
|
110
118
|
c = options[:connection] || Faraday.default_connection
|
111
119
|
|
@@ -117,8 +125,11 @@ module Google
|
|
117
125
|
self.refresh_token = nil
|
118
126
|
self.expires_at = 0
|
119
127
|
else
|
120
|
-
raise(
|
121
|
-
|
128
|
+
raise AuthorizationError.with_details(
|
129
|
+
"Unexpected error code #{resp.status}",
|
130
|
+
credential_type_name: self.class.name,
|
131
|
+
principal: principal
|
132
|
+
)
|
122
133
|
end
|
123
134
|
end
|
124
135
|
end
|
@@ -157,6 +168,13 @@ module Google
|
|
157
168
|
|
158
169
|
self
|
159
170
|
end
|
171
|
+
|
172
|
+
# Returns the client ID as the principal for user refresh credentials
|
173
|
+
# @private
|
174
|
+
# @return [String, Symbol] the client ID or :user_refresh if not available
|
175
|
+
def principal
|
176
|
+
@client_id || :user_refresh
|
177
|
+
end
|
160
178
|
end
|
161
179
|
end
|
162
180
|
end
|
data/lib/googleauth/version.rb
CHANGED
@@ -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 [
|
185
|
-
#
|
186
|
-
#
|
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
|
-
|
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
|
231
|
-
|
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
|
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.
|
4
|
+
version: 1.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Google LLC
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
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: '
|
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: '
|
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.
|
208
|
+
rubygems_version: 3.6.9
|
206
209
|
specification_version: 4
|
207
210
|
summary: Google Auth Library for Ruby
|
208
211
|
test_files: []
|