Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Deprecate the positional argument for callback_uri, and introduce keyword argument instead #475

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/googleauth/user_authorizer.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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