Skip to content

Commit

Permalink
feat: Deprecate the positional argument for callback_uri, and introdu…
Browse files Browse the repository at this point in the history
…ce keyword argument instead (#475)
  • Loading branch information
bajajneha27 committed Feb 9, 2024
1 parent 8a83cd1 commit d078a54
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
12 changes: 8 additions & 4 deletions lib/googleauth/user_authorizer.rb
Expand Up @@ -55,21 +55,25 @@ 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

Expand Down
15 changes: 11 additions & 4 deletions lib/googleauth/web_user_authorizer.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/googleauth/user_authorizer_spec.rb
Expand Up @@ -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"
Expand Down

0 comments on commit d078a54

Please sign in to comment.