From 78a38330d6007a604984ad7dce39018e7e5c309f Mon Sep 17 00:00:00 2001 From: bajajnehaa Date: Thu, 8 Feb 2024 10:20:19 +0000 Subject: [PATCH 1/2] feat: Deprecate the positional argument for callback_uri, and introduce keyword argument --- lib/googleauth/user_authorizer.rb | 13 +++++++++---- lib/googleauth/web_user_authorizer.rb | 15 +++++++++++---- spec/googleauth/user_authorizer_spec.rb | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lib/googleauth/user_authorizer.rb b/lib/googleauth/user_authorizer.rb index e6948d5..ba9d036 100644 --- a/lib/googleauth/user_authorizer.rb +++ b/lib/googleauth/user_authorizer.rb @@ -55,22 +55,27 @@ class UserAuthorizer # Authorization scope to request # @param [Google::Auth::Stores::TokenStore] token_store # Backing storage for persisting user credentials - # @param [String] callback_uri + # @param [String] legacy_callback_uri # URL (either absolute or relative) of the auth callback. - # Defaults to '/oauth2callback' + # Defaults to '/oauth2callback'. + # @deprecated This field is deprecated. Instead, use the keyword + # argument callback_uri. # @param [String] code_verifier # Random string of 43-128 chars used to verify the key exchange using # PKCE. def initialize client_id, scope, token_store, - callback_uri = nil, code_verifier: nil + legacy_callback_uri = nil, + callback_uri: nil, + code_verifier: nil raise NIL_CLIENT_ID_ERROR if client_id.nil? raise NIL_SCOPE_ERROR if scope.nil? @client_id = client_id @scope = Array(scope) @token_store = token_store - @callback_uri = callback_uri || "/oauth2callback" + @callback_uri = legacy_callback_uri || callback_uri || "/oauth2callback" @code_verifier = code_verifier + end # Build the URL for requesting authorization. diff --git a/lib/googleauth/web_user_authorizer.rb b/lib/googleauth/web_user_authorizer.rb index ddf9644..75183c3 100644 --- a/lib/googleauth/web_user_authorizer.rb +++ b/lib/googleauth/web_user_authorizer.rb @@ -93,15 +93,22 @@ def self.handle_auth_callback_deferred request # Authorization scope to request # @param [Google::Auth::Stores::TokenStore] token_store # Backing storage for persisting user credentials - # @param [String] callback_uri + # @param [String] legacy_callback_uri # URL (either absolute or relative) of the auth callback. Defaults - # to '/oauth2callback' + # to '/oauth2callback'. + # @deprecated This field is deprecated. Instead, use the keyword + # argument callback_uri. # @param [String] code_verifier # Random string of 43-128 chars used to verify the key exchange using # PKCE. def initialize client_id, scope, token_store, - callback_uri = nil, code_verifier: nil - super client_id, scope, token_store, callback_uri, code_verifier: code_verifier + legacy_callback_uri = nil, + callback_uri: nil, + code_verifier: nil + super client_id, scope, token_store, + legacy_callback_uri, + code_verifier: code_verifier, + callback_uri: callback_uri end # Handle the result of the oauth callback. Exchanges the authorization diff --git a/spec/googleauth/user_authorizer_spec.rb b/spec/googleauth/user_authorizer_spec.rb index 2a176ae..9fb3157 100644 --- a/spec/googleauth/user_authorizer_spec.rb +++ b/spec/googleauth/user_authorizer_spec.rb @@ -85,7 +85,7 @@ Google::Auth::UserAuthorizer.new(client_id, scope, token_store, - callback_uri) + callback_uri: callback_uri) end let :uri do authorizer.get_authorization_url login_hint: "user1", state: "mystate" From d07b528976bc733f43e868a36f8d59d643f6a8f4 Mon Sep 17 00:00:00 2001 From: bajajnehaa Date: Thu, 8 Feb 2024 14:03:52 +0000 Subject: [PATCH 2/2] fix CI failure --- lib/googleauth/user_authorizer.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/googleauth/user_authorizer.rb b/lib/googleauth/user_authorizer.rb index ba9d036..ccd24d9 100644 --- a/lib/googleauth/user_authorizer.rb +++ b/lib/googleauth/user_authorizer.rb @@ -75,7 +75,6 @@ def initialize client_id, scope, token_store, @token_store = token_store @callback_uri = legacy_callback_uri || callback_uri || "/oauth2callback" @code_verifier = code_verifier - end # Build the URL for requesting authorization.