googleauth 1.11.0 → 1.11.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4912a601c0a234fa9faf150d7461cab993f775b715f6ac7d19db017ceae74e6d
4
- data.tar.gz: e08da21e12d58260944079d068a04099fa0c812eb486e760a3ab12dd002700f4
3
+ metadata.gz: 1cfe9034bbf9362f45a8489765bee5b8253deb27c75d50a43b01a4ff3f46a002
4
+ data.tar.gz: e5bd5f777b3caa2aeae4d42e0576d8f10295cba035736f741399db80a58c50e0
5
5
  SHA512:
6
- metadata.gz: b0346fcaf38cb783fd4d22f0734994298d63dfa1a89fd34df4d4f42b87160de410e34c93ab4773c3bbaf03b41160f10e3fd5bc0fa137d1ab6fb5dce15f72ba53
7
- data.tar.gz: c5ff10a04491e9f56dff9bcea24c67398e67713efc89c2d378075621da837b59c5fdbd36c0b97d5753fd0358befe8ce2ceacc86af1cce0a1c54d609d916903c6
6
+ metadata.gz: 1bf31f0d2c50d10cbb1f2e0aec62bb720e0274b518617d0263e30c0952c72589784102a09f251a11996eb7c05181b1639b685803c575d1090c55ce573a62a9d7
7
+ data.tar.gz: e941dad8ae8e72483587a28d014870a694773dac46aa77f8a8ce0e7fabd2202f82d08e5b1bbc062a4e748effa40fb21f450b4b1b5e423cc66ea76ec04b1c2e23
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Release History
2
2
 
3
+ ### 1.11.2 (2024-10-23)
4
+
5
+ #### Bug Fixes
6
+
7
+ * Temporarily disable universe domain query from GCE metadata server ([#493](https://github.com/googleapis/google-auth-library-ruby/issues/493))
8
+ * Use updated metadata path for universe-domain ([#496](https://github.com/googleapis/google-auth-library-ruby/issues/496))
9
+
10
+ ### 1.11.1 (2024-10-04)
11
+
12
+ #### Bug Fixes
13
+
14
+ * Fixed parsing of expiration timestamp from ID tokens ([#492](https://github.com/googleapis/google-auth-library-ruby/issues/492))
15
+ * Use NoMethodError instead of NotImplementedError for unimplemented base class methods ([#487](https://github.com/googleapis/google-auth-library-ruby/issues/487))
16
+
3
17
  ### 1.11.0 (2024-02-09)
4
18
 
5
19
  #### Features
@@ -63,17 +63,17 @@ module Google
63
63
  end
64
64
 
65
65
  def expires_within?
66
- raise NotImplementedError
66
+ raise NoMethodError, "expires_within? not implemented"
67
67
  end
68
68
 
69
69
  private
70
70
 
71
71
  def token_type
72
- raise NotImplementedError
72
+ raise NoMethodError, "token_type not implemented"
73
73
  end
74
74
 
75
75
  def fetch_access_token!
76
- raise NotImplementedError
76
+ raise NoMethodError, "fetch_access_token! not implemented"
77
77
  end
78
78
  end
79
79
  end
@@ -80,11 +80,16 @@ module Google
80
80
  alias unmemoize_all reset_cache
81
81
  end
82
82
 
83
+ # @private Temporary; remove when universe domain metadata endpoint is stable (see b/349488459).
84
+ attr_accessor :disable_universe_domain_check
85
+
83
86
  # Construct a GCECredentials
84
87
  def initialize options = {}
85
88
  # Override the constructor to remember whether the universe domain was
86
89
  # overridden by a constructor argument.
87
90
  @universe_domain_overridden = options["universe_domain"] || options[:universe_domain] ? true : false
91
+ # TODO: Remove when universe domain metadata endpoint is stable (see b/349488459).
92
+ @disable_universe_domain_check = true
88
93
  super options
89
94
  end
90
95
 
@@ -123,26 +128,47 @@ module Google
123
128
  def build_token_hash body, content_type, retrieval_time
124
129
  hash =
125
130
  if ["text/html", "application/text"].include? content_type
126
- { token_type.to_s => body }
131
+ parse_encoded_token body
127
132
  else
128
133
  Signet::OAuth2.parse_credentials body, content_type
129
134
  end
130
- unless @universe_domain_overridden
131
- universe_domain = Google::Cloud.env.lookup_metadata "universe", "universe_domain"
132
- universe_domain = "googleapis.com" if !universe_domain || universe_domain.empty?
133
- hash["universe_domain"] = universe_domain.strip
134
- end
135
- # The response might have been cached, which means expires_in might be
136
- # stale. Update it based on the time since the data was retrieved.
137
- # We also ensure expires_in is conservative; subtracting at least 1
138
- # second to offset any skew from metadata server latency.
139
- if hash["expires_in"].is_a? Numeric
140
- offset = 1 + (Process.clock_gettime(Process::CLOCK_MONOTONIC) - retrieval_time).round
141
- hash["expires_in"] -= offset if offset.positive?
142
- hash["expires_in"] = 0 if hash["expires_in"].negative?
135
+ add_universe_domain_to hash
136
+ adjust_for_stale_expires_in hash, retrieval_time
137
+ hash
138
+ end
139
+
140
+ def parse_encoded_token body
141
+ hash = { token_type.to_s => body }
142
+ if token_type == :id_token
143
+ expires_at = expires_at_from_id_token body
144
+ hash["expires_at"] = expires_at if expires_at
143
145
  end
144
146
  hash
145
147
  end
148
+
149
+ def add_universe_domain_to hash
150
+ return if @universe_domain_overridden
151
+ universe_domain =
152
+ if disable_universe_domain_check
153
+ # TODO: Remove when universe domain metadata endpoint is stable (see b/349488459).
154
+ "googleapis.com"
155
+ else
156
+ Google::Cloud.env.lookup_metadata "universe", "universe-domain"
157
+ end
158
+ universe_domain = "googleapis.com" if !universe_domain || universe_domain.empty?
159
+ hash["universe_domain"] = universe_domain.strip
160
+ end
161
+
162
+ # The response might have been cached, which means expires_in might be
163
+ # stale. Update it based on the time since the data was retrieved.
164
+ # We also ensure expires_in is conservative; subtracting at least 1
165
+ # second to offset any skew from metadata server latency.
166
+ def adjust_for_stale_expires_in hash, retrieval_time
167
+ return unless hash["expires_in"].is_a? Numeric
168
+ offset = 1 + (Process.clock_gettime(Process::CLOCK_MONOTONIC) - retrieval_time).round
169
+ hash["expires_in"] -= offset if offset.positive?
170
+ hash["expires_in"] = 0 if hash["expires_in"].negative?
171
+ end
146
172
  end
147
173
  end
148
174
  end
@@ -299,6 +299,12 @@ module Google
299
299
  #
300
300
  attr_reader :quota_project_id
301
301
 
302
+ # @private Temporary; remove when universe domain metadata endpoint is stable (see b/349488459).
303
+ def disable_universe_domain_check
304
+ return false unless @client.respond_to? :disable_universe_domain_check
305
+ @client.disable_universe_domain_check
306
+ end
307
+
302
308
  # @private Delegate client methods to the client object.
303
309
  extend Forwardable
304
310
 
@@ -76,7 +76,7 @@ module Google
76
76
  # The retrieved subject token.
77
77
  #
78
78
  def retrieve_subject_token!
79
- raise NotImplementedError
79
+ raise NoMethodError, "retrieve_subject_token! not implemented"
80
80
  end
81
81
 
82
82
  # Returns whether the credentials represent a workforce pool (True) or
@@ -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 "base64"
16
+ require "json"
15
17
  require "signet/oauth_2/client"
16
18
  require "googleauth/base_client"
17
19
 
@@ -29,6 +31,8 @@ module Signet
29
31
 
30
32
  def update_token! options = {}
31
33
  options = deep_hash_normalize options
34
+ id_token_expires_at = expires_at_from_id_token options[:id_token]
35
+ options[:expires_at] = id_token_expires_at if id_token_expires_at
32
36
  update_token_signet_base options
33
37
  self.universe_domain = options[:universe_domain] if options.key? :universe_domain
34
38
  self
@@ -89,6 +93,19 @@ module Signet
89
93
  end
90
94
  end
91
95
  end
96
+
97
+ private
98
+
99
+ def expires_at_from_id_token id_token
100
+ match = /^[\w=-]+\.([\w=-]+)\.[\w=-]+$/.match id_token.to_s
101
+ return unless match
102
+ json = JSON.parse Base64.urlsafe_decode64 match[1]
103
+ return unless json.key? "exp"
104
+ Time.at json["exp"].to_i
105
+ rescue StandardError
106
+ # Shouldn't happen unless we get a garbled ID token
107
+ nil
108
+ end
92
109
  end
93
110
  end
94
111
  end
@@ -29,7 +29,7 @@ module Google
29
29
  # @return [String]
30
30
  # The loaded token data.
31
31
  def load _id
32
- raise "Not implemented"
32
+ raise NoMethodError, "load not implemented"
33
33
  end
34
34
 
35
35
  # Put the token data into storage for the given ID.
@@ -39,7 +39,7 @@ module Google
39
39
  # @param [String] token
40
40
  # The token data to store.
41
41
  def store _id, _token
42
- raise "Not implemented"
42
+ raise NoMethodError, "store not implemented"
43
43
  end
44
44
 
45
45
  # Remove the token data from storage for the given ID.
@@ -47,7 +47,7 @@ module Google
47
47
  # @param [String] id
48
48
  # ID of the token data to delete
49
49
  def delete _id
50
- raise "Not implemented"
50
+ raise NoMethodError, "delete not implemented"
51
51
  end
52
52
  end
53
53
  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.11.0".freeze
19
+ VERSION = "1.11.2".freeze
20
20
  end
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googleauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Emiola
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-14 00:00:00.000000000 Z
11
+ date: 2024-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0'
188
188
  requirements: []
189
- rubygems_version: 3.5.3
189
+ rubygems_version: 3.5.21
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: Google Auth Library for Ruby