Skip to content

Commit

Permalink
fix: use client.site instead of the callback_url
Browse files Browse the repository at this point in the history
By using client.site instead of callback_url we can preserve any query string parameters that could be included within the site key and also configured in the callback url within the user pool client app
  • Loading branch information
coatezy committed Mar 26, 2024
1 parent 9881dbc commit 73890ed
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/omniauth/strategies/cognito_idp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CognitoIdP < OmniAuth::Strategies::OAuth2
def build_access_token
client.auth_code.get_token(
request.params['code'],
{ redirect_uri: callback_url.split('?').first }.merge(token_params.to_hash(symbolize_keys: true)),
{ redirect_uri: client.site }.merge(token_params.to_hash(symbolize_keys: true)),
deep_symbolize(options.auth_token_params)
)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/omniauth/strategies/cognito_idp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
end
end

let(:oauth_client) { double('OAuth2::Client', auth_code: auth_code) }
let(:oauth_client) { double('OAuth2::Client', auth_code: auth_code, site: "http://localhost/auth/cognito-idp/callback") }
let(:auth_code) { double('OAuth2::AuthCode', get_token: access_token_object) }
let(:access_token_object) { double('OAuth2::AccessToken') }
let(:callback_url) { 'http://localhost/auth/cognito-idp/callback?code=1234' }
Expand All @@ -57,7 +57,7 @@
let(:env) { {} }
let(:request) { double('Rack::Request', params: {'state' => strategy.session['omniauth.state']}) }
let(:session) { { 'omniauth.state' => 'some_state' } }
let(:oauth_client) { double('OAuth2::Client', auth_code: auth_code) }
let(:oauth_client) { double('OAuth2::Client', auth_code: auth_code, site: "http://localhost/auth/cognito-idp/callback") }
let(:auth_code) { double('OAuth2::AuthCode') }
let(:access_token_object) { OAuth2::AccessToken.from_hash(oauth_client, token_hash) }

Expand Down

0 comments on commit 73890ed

Please sign in to comment.