googleauth 1.3.0 → 1.13.1

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: 0bc48c47d78d7ec955a2a5557fc8f1cff502a28dd1e18c5af3fc566be5743171
4
- data.tar.gz: 220a8fed81a73d5bc93a2fca2951a749b9469cb769a198cf13564ad7f714ac90
3
+ metadata.gz: 6d8ca5b2b0c7f4ce54f7971d8de2f23f3ee0837d08d7d3c568c503308fcf82ab
4
+ data.tar.gz: d5f8b8fd2fcb4fef4240db58bf90f54a8bfd021c550a7bc9063c9087285f3921
5
5
  SHA512:
6
- metadata.gz: 73f52ffce21a05e15102b54aabbcb3cb199d32e9caf318b125b48b6caeddc01f77c3de4ea09513b0b1e9e503c912e55adf5864b4295b86af0620aa0c7df25df4
7
- data.tar.gz: 7ec107faa35d72aa1fd8e79b86b30df9acf061ce86ac52641bc12b69391f0b4f2adde8021b908327e379dee65c1e2ed7ed1b203e629ca1f4d25a988e80c31eb2
6
+ metadata.gz: 6a4de2b23f4dc0310a18568e0618c5d81fad54dfc8d57fe3c27b954c4bd21272fcc467c2c313f98f80fa127eab11ebe0d0fc55ceed7e6c5439764500e334df49
7
+ data.tar.gz: f4aff68138105ea19875bb7a51d4b6ced9ec2e7185ce725eca205ea1dc11beb9e6019c9dd89449866598ca6e4d3abb06b91f277f34e51ac7726d79a39fc40c67
data/CHANGELOG.md CHANGED
@@ -1,5 +1,145 @@
1
1
  # Release History
2
2
 
3
+ ### 1.13.1 (2025-01-24)
4
+
5
+ #### Bug Fixes
6
+
7
+ * Signet client subclasses no longer make the update! method private ([#516](https://github.com/googleapis/google-auth-library-ruby/issues/516))
8
+
9
+ ### 1.13.0 (2025-01-22)
10
+
11
+ #### Features
12
+
13
+ * create impersonated service credentials ([#499](https://github.com/googleapis/google-auth-library-ruby/issues/499))
14
+ #### Documentation
15
+
16
+ * Include note about validating externally-provided credentials ([#512](https://github.com/googleapis/google-auth-library-ruby/issues/512))
17
+
18
+ ### 1.12.2 (2024-12-19)
19
+
20
+ #### Bug Fixes
21
+
22
+ * GCECredentials lazily fetches from the metadata server to ensure a universe domain is known ([#509](https://github.com/googleapis/google-auth-library-ruby/issues/509))
23
+
24
+ ### 1.12.1 (2024-12-17)
25
+
26
+ #### Bug Fixes
27
+
28
+ * Restored previous behavior where the apply! method returns the auth header ([#506](https://github.com/googleapis/google-auth-library-ruby/issues/506))
29
+
30
+ ### 1.12.0 (2024-12-05)
31
+
32
+ #### Features
33
+
34
+ * provided opt-in debug logging ([#490](https://github.com/googleapis/google-auth-library-ruby/issues/490))
35
+
36
+ ### 1.11.2 (2024-10-23)
37
+
38
+ #### Bug Fixes
39
+
40
+ * Temporarily disable universe domain query from GCE metadata server ([#493](https://github.com/googleapis/google-auth-library-ruby/issues/493))
41
+ * Use updated metadata path for universe-domain ([#496](https://github.com/googleapis/google-auth-library-ruby/issues/496))
42
+
43
+ ### 1.11.1 (2024-10-04)
44
+
45
+ #### Bug Fixes
46
+
47
+ * Fixed parsing of expiration timestamp from ID tokens ([#492](https://github.com/googleapis/google-auth-library-ruby/issues/492))
48
+ * Use NoMethodError instead of NotImplementedError for unimplemented base class methods ([#487](https://github.com/googleapis/google-auth-library-ruby/issues/487))
49
+
50
+ ### 1.11.0 (2024-02-09)
51
+
52
+ #### Features
53
+
54
+ * Deprecate the positional argument for callback_uri, and introduce keyword argument instead ([#475](https://github.com/googleapis/google-auth-library-ruby/issues/475))
55
+
56
+ ### 1.10.0 (2024-02-08)
57
+
58
+ #### Features
59
+
60
+ * add PKCE to 3 Legged OAuth exchange ([#471](https://github.com/googleapis/google-auth-library-ruby/issues/471))
61
+ #### Bug Fixes
62
+
63
+ * Client library credentials provide correct self-signed JWT and external account behavior when loading from a file path or JSON data ([#474](https://github.com/googleapis/google-auth-library-ruby/issues/474))
64
+ * Prioritize universe domain specified in GCECredentials arguments over metadata-fetched value ([#472](https://github.com/googleapis/google-auth-library-ruby/issues/472))
65
+
66
+ ### 1.9.2 (2024-01-25)
67
+
68
+ #### Bug Fixes
69
+
70
+ * Prevent access tokens from being fetched at service account construction in the self-signed-jwt case ([#467](https://github.com/googleapis/google-auth-library-ruby/issues/467))
71
+
72
+ ### 1.9.1 (2023-12-12)
73
+
74
+ #### Bug Fixes
75
+
76
+ * update expires_in for cached metadata-retrieved tokens ([#464](https://github.com/googleapis/google-auth-library-ruby/issues/464))
77
+
78
+ ### 1.9.0 (2023-12-07)
79
+
80
+ #### Features
81
+
82
+ * Include universe_domain in credentials ([#460](https://github.com/googleapis/google-auth-library-ruby/issues/460))
83
+ * Use google-cloud-env for more robust Metadata Service access ([#459](https://github.com/googleapis/google-auth-library-ruby/issues/459))
84
+
85
+ ### 1.8.1 (2023-09-19)
86
+
87
+ #### Documentation
88
+
89
+ * improve ADC related error and warning messages ([#452](https://github.com/googleapis/google-auth-library-ruby/issues/452))
90
+
91
+ ### 1.8.0 (2023-09-07)
92
+
93
+ #### Features
94
+
95
+ * Pass additional parameters to auhtorization url ([#447](https://github.com/googleapis/google-auth-library-ruby/issues/447))
96
+ #### Documentation
97
+
98
+ * improve ADC related error and warning messages ([#449](https://github.com/googleapis/google-auth-library-ruby/issues/449))
99
+
100
+ ### 1.7.0 (2023-07-14)
101
+
102
+ #### Features
103
+
104
+ * Adding support for pluggable auth credentials ([#437](https://github.com/googleapis/google-auth-library-ruby/issues/437))
105
+ #### Documentation
106
+
107
+ * fixed iss argument and description in comments of IDTokens ([#438](https://github.com/googleapis/google-auth-library-ruby/issues/438))
108
+
109
+ ### 1.6.0 (2023-06-20)
110
+
111
+ #### Features
112
+
113
+ * adding identity pool credentials ([#433](https://github.com/googleapis/google-auth-library-ruby/issues/433))
114
+ #### Documentation
115
+
116
+ * deprecation message for discontinuing command line auth flow ([#435](https://github.com/googleapis/google-auth-library-ruby/issues/435))
117
+
118
+ ### 1.5.2 (2023-04-13)
119
+
120
+ #### Bug Fixes
121
+
122
+ * AWS IMDSV2 session token fetching shall call PUT method instead of GET ([#429](https://github.com/googleapis/google-auth-library-ruby/issues/429))
123
+ * GCECredentials - Allow retrieval of ID token ([#425](https://github.com/googleapis/google-auth-library-ruby/issues/425))
124
+
125
+ ### 1.5.1 (2023-04-10)
126
+
127
+ #### Bug Fixes
128
+
129
+ * Remove external account config validation ([#427](https://github.com/googleapis/google-auth-library-ruby/issues/427))
130
+
131
+ ### 1.5.0 (2023-03-21)
132
+
133
+ #### Features
134
+
135
+ * Add support for AWS Workload Identity Federation ([#418](https://github.com/googleapis/google-auth-library-ruby/issues/418))
136
+
137
+ ### 1.4.0 (2022-12-14)
138
+
139
+ #### Features
140
+
141
+ * make new_jwt_token public in order to fetch raw token directly ([#405](https://github.com/googleapis/google-auth-library-ruby/issues/405))
142
+
3
143
  ### 1.3.0 (2022-10-18)
4
144
 
5
145
  #### Features
data/README.md CHANGED
@@ -64,6 +64,15 @@ well as a web variant tailored toward Rack-based applications.
64
64
  The authorizers are intended for authorization use cases. For sign-on,
65
65
  see [Google Identity Platform](https://developers.google.com/identity/)
66
66
 
67
+ ## Important notes
68
+
69
+ If you accept a credential configuration (credential JSON/File/Stream) from an
70
+ external source for authentication to Google Cloud, you must validate it before
71
+ providing it to any Google API or library. Providing an unvalidated credential
72
+ configuration to Google APIs can compromise the security of your systems and data.
73
+ For more information, refer to [Validate credential configurations from external
74
+ sources](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials).
75
+
67
76
  ### Example (Web)
68
77
 
69
78
  ```ruby
@@ -97,7 +106,48 @@ get('/oauth2callback') do
97
106
  end
98
107
  ```
99
108
 
100
- ### Example (Command Line)
109
+ ### Example (Web with PKCE)
110
+
111
+ Proof Key for Code Exchange (PKCE) is an [RFC](https://www.rfc-editor.org/rfc/rfc7636) that aims to prevent malicious operating system processes from hijacking an OAUTH 2.0 exchange. PKCE mitigates the above vulnerability by including `code_challenge` and `code_challenge_method` parameters in the Authorization Request and a `code_verifier` parameter in the Access Token Request.
112
+
113
+ ```ruby
114
+ require 'googleauth'
115
+ require 'googleauth/web_user_authorizer'
116
+ require 'googleauth/stores/redis_token_store'
117
+ require 'redis'
118
+
119
+ client_id = Google::Auth::ClientId.from_file('/path/to/client_secrets.json')
120
+ scope = ['https://www.googleapis.com/auth/drive']
121
+ token_store = Google::Auth::Stores::RedisTokenStore.new(redis: Redis.new)
122
+ authorizer = Google::Auth::WebUserAuthorizer.new(
123
+ client_id, scope, token_store, '/oauth2callback')
124
+
125
+
126
+ get('/authorize') do
127
+ # NOTE: Assumes the user is already authenticated to the app
128
+ user_id = request.session['user_id']
129
+ # User needs to take care of generating the code_verifier and storing it in
130
+ # the session.
131
+ request.session['code_verifier'] ||= Google::Auth::WebUserAuthorizer.generate_code_verifier
132
+ authorizer.code_verifier = request.session['code_verifier']
133
+ credentials = authorizer.get_credentials(user_id, request)
134
+ if credentials.nil?
135
+ redirect authorizer.get_authorization_url(login_hint: user_id, request: request)
136
+ end
137
+ # Credentials are valid, can call APIs
138
+ # ...
139
+ end
140
+
141
+ get('/oauth2callback') do
142
+ target_url = Google::Auth::WebUserAuthorizer.handle_auth_callback_deferred(
143
+ request)
144
+ redirect target_url
145
+ end
146
+ ```
147
+
148
+ ### Example (Command Line) [Deprecated]
149
+
150
+ The Google Auth OOB flow has been discontiued on January 31, 2023. The OOB flow is a legacy flow that is no longer considered secure. To continue using Google Auth, please migrate your applications to a more secure flow. For more information on how to do this, please refer to this [OOB Migration](https://developers.google.com/identity/protocols/oauth2/resources/oob-migration) guide.
101
151
 
102
152
  ```ruby
103
153
  require 'googleauth'
@@ -241,6 +291,6 @@ hesitate to
241
291
  [ask questions](http://stackoverflow.com/questions/tagged/google-auth-library-ruby)
242
292
  about the client or APIs on [StackOverflow](http://stackoverflow.com).
243
293
 
244
- [application default credentials]: https://developers.google.com/accounts/docs/application-default-credentials
294
+ [application default credentials]: https://cloud.google.com/docs/authentication/provide-credentials-adc
245
295
  [contributing]: https://github.com/googleapis/google-auth-library-ruby/tree/main/.github/CONTRIBUTING.md
246
296
  [license]: https://github.com/googleapis/google-auth-library-ruby/tree/main/LICENSE
@@ -20,9 +20,9 @@ module Google
20
20
  # used to access Google APIs.
21
21
  module Auth
22
22
  NOT_FOUND_ERROR = <<~ERROR_MESSAGE.freeze
23
- Could not load the default credentials. Browse to
24
- https://developers.google.com/accounts/docs/application-default-credentials
25
- for more information
23
+ Your credentials were not found. To set up Application Default
24
+ Credentials for your environment, see
25
+ https://cloud.google.com/docs/authentication/external/set-up-adc
26
26
  ERROR_MESSAGE
27
27
 
28
28
  module_function
@@ -55,12 +55,8 @@ module Google
55
55
  DefaultCredentials.from_well_known_path(scope, options) ||
56
56
  DefaultCredentials.from_system_default_path(scope, options)
57
57
  return creds unless creds.nil?
58
- unless GCECredentials.on_gce? options
59
- # Clear cache of the result of GCECredentials.on_gce?
60
- GCECredentials.unmemoize_all
61
- raise NOT_FOUND_ERROR
62
- end
63
- GCECredentials.new scope: scope
58
+ raise NOT_FOUND_ERROR unless GCECredentials.on_gce? options
59
+ GCECredentials.new options.merge(scope: scope)
64
60
  end
65
61
  end
66
62
  end
@@ -0,0 +1,92 @@
1
+ # Copyright 2023 Google, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require "google/logging/message"
16
+
17
+ module Google
18
+ # Module Auth provides classes that provide Google-specific authorization
19
+ # used to access Google APIs.
20
+ module Auth
21
+ # BaseClient is a class used to contain common methods that are required by any
22
+ # Credentials Client, including AwsCredentials, ServiceAccountCredentials,
23
+ # and UserRefreshCredentials. This is a superclass of Signet::OAuth2::Client
24
+ # and has been created to create a generic interface for all credentials clients
25
+ # to use, including ones which do not inherit from Signet::OAuth2::Client.
26
+ module BaseClient
27
+ AUTH_METADATA_KEY = :authorization
28
+
29
+ # Updates a_hash updated with the authentication token
30
+ def apply! a_hash, opts = {}
31
+ # fetch the access token there is currently not one, or if the client
32
+ # has expired
33
+ fetch_access_token! opts if needs_access_token?
34
+ token = send token_type
35
+ a_hash[AUTH_METADATA_KEY] = "Bearer #{token}"
36
+ logger&.debug do
37
+ hash = Digest::SHA256.hexdigest token
38
+ Google::Logging::Message.from message: "Sending auth token. (sha256:#{hash})"
39
+ end
40
+
41
+ a_hash[AUTH_METADATA_KEY]
42
+ end
43
+
44
+ # Returns a clone of a_hash updated with the authentication token
45
+ def apply a_hash, opts = {}
46
+ a_copy = a_hash.clone
47
+ apply! a_copy, opts
48
+ a_copy
49
+ end
50
+
51
+ # Whether the id_token or access_token is missing or about to expire.
52
+ def needs_access_token?
53
+ send(token_type).nil? || expires_within?(60)
54
+ end
55
+
56
+ # Returns a reference to the #apply method, suitable for passing as
57
+ # a closure
58
+ def updater_proc
59
+ proc { |a_hash, opts = {}| apply a_hash, opts }
60
+ end
61
+
62
+ def on_refresh &block
63
+ @refresh_listeners = [] unless defined? @refresh_listeners
64
+ @refresh_listeners << block
65
+ end
66
+
67
+ def notify_refresh_listeners
68
+ listeners = defined?(@refresh_listeners) ? @refresh_listeners : []
69
+ listeners.each do |block|
70
+ block.call self
71
+ end
72
+ end
73
+
74
+ def expires_within?
75
+ raise NoMethodError, "expires_within? not implemented"
76
+ end
77
+
78
+ # The logger used to log operations on this client, such as token refresh.
79
+ attr_accessor :logger
80
+
81
+ private
82
+
83
+ def token_type
84
+ raise NoMethodError, "token_type not implemented"
85
+ end
86
+
87
+ def fetch_access_token!
88
+ raise NoMethodError, "fetch_access_token! not implemented"
89
+ end
90
+ end
91
+ end
92
+ end
@@ -17,51 +17,67 @@ require "googleauth/credentials_loader"
17
17
 
18
18
  module Google
19
19
  module Auth
20
- # Representation of an application's identity for user authorization
21
- # flows.
20
+ ##
21
+ # Representation of an application's identity for user authorization flows.
22
+ #
22
23
  class ClientId
24
+ # Toplevel JSON key for the an installed app configuration.
25
+ # Must include client_id and client_secret subkeys if present.
23
26
  INSTALLED_APP = "installed".freeze
27
+ # Toplevel JSON key for the a webapp configuration.
28
+ # Must include client_id and client_secret subkeys if present.
24
29
  WEB_APP = "web".freeze
30
+ # JSON key for the client ID within an app configuration.
25
31
  CLIENT_ID = "client_id".freeze
32
+ # JSON key for the client secret within an app configuration.
26
33
  CLIENT_SECRET = "client_secret".freeze
34
+ # An error message raised when none of the expected toplevel properties
35
+ # can be found.
27
36
  MISSING_TOP_LEVEL_ELEMENT_ERROR =
28
37
  "Expected top level property 'installed' or 'web' to be present.".freeze
29
38
 
39
+ ##
30
40
  # Text identifier of the client ID
31
41
  # @return [String]
42
+ #
32
43
  attr_reader :id
33
44
 
45
+ ##
34
46
  # Secret associated with the client ID
35
47
  # @return [String]
48
+ #
36
49
  attr_reader :secret
37
50
 
38
51
  class << self
39
52
  attr_accessor :default
40
53
  end
41
54
 
42
- # Initialize the Client ID
55
+ ##
56
+ # Initialize the Client ID. Both id and secret must be non-nil.
43
57
  #
44
58
  # @param [String] id
45
59
  # Text identifier of the client ID
46
60
  # @param [String] secret
47
61
  # Secret associated with the client ID
48
- # @note Direction instantion is discouraged to avoid embedding IDs
49
- # & secrets in source. See {#from_file} to load from
62
+ # @note Direct instantiation is discouraged to avoid embedding IDs
63
+ # and secrets in source. See {#from_file} to load from
50
64
  # `client_secrets.json` files.
65
+ #
51
66
  def initialize id, secret
52
- CredentialsLoader.warn_if_cloud_sdk_credentials id
53
67
  raise "Client id can not be nil" if id.nil?
54
68
  raise "Client secret can not be nil" if secret.nil?
55
69
  @id = id
56
70
  @secret = secret
57
71
  end
58
72
 
73
+ ##
59
74
  # Constructs a Client ID from a JSON file downloaded from the
60
75
  # Google Developers Console.
61
76
  #
62
77
  # @param [String, File] file
63
78
  # Path of file to read from
64
79
  # @return [Google::Auth::ClientID]
80
+ #
65
81
  def self.from_file file
66
82
  raise "File can not be nil." if file.nil?
67
83
  File.open file.to_s do |f|
@@ -71,13 +87,14 @@ module Google
71
87
  end
72
88
  end
73
89
 
90
+ ##
74
91
  # Constructs a Client ID from a previously loaded JSON file. The hash
75
- # structure should
76
- # match the expected JSON format.
92
+ # structure should match the expected JSON format.
77
93
  #
78
94
  # @param [hash] config
79
95
  # Parsed contents of the JSON file
80
96
  # @return [Google::Auth::ClientID]
97
+ #
81
98
  def self.from_hash config
82
99
  raise "Hash can not be nil." if config.nil?
83
100
  raw_detail = config[INSTALLED_APP] || config[WEB_APP]