asanghi / omniauth-constantcontact2

OmniAuth Strategy for Constant Contact using OAuth2
MIT License
5 stars 18 forks source link

redirect_uri_mismatch during Access Token Request #9

Open kpheasey opened 3 years ago

kpheasey commented 3 years ago

I'm running into a problem where I get a redirect_uri_mismatch error during the callback phase, after granting access on CC. CC is redirecting back to my development server, but when we can't get an access token.

Constant Contact app settings: Redirect URI: http://localhost:5000/companies/auth/constantcontact/callback Callback URL: http://localhost:5000/companies/auth/constantcontact/callback

12:49:38 web.1     | Started GET "/companies/auth/constantcontact" for 127.0.0.1 at 2020-09-18 12:49:38 -0400
12:49:38 web.1     | I, [2020-09-18T12:49:38.462547 #37780]  INFO -- omniauth: (constantcontact) Request phase initiated.
12:49:48 web.1     | Started GET "/companies/auth/constantcontact/callback?code=123&state=456&username=kevin%40kpsoftware.io" for 127.0.0.1 at 2020-09-18 12:49:48 -0400
12:49:48 web.1     | I, [2020-09-18T12:49:48.692383 #37780]  INFO -- omniauth: (constantcontact) Callback phase initiated.
12:49:48 web.1     | E, [2020-09-18T12:49:48.818707 #37780] ERROR -- omniauth: (constantcontact) Authentication failure! invalid_credentials: OAuth2::Error, redirect_uri_mismatch: Redirect URI mismatch.
12:49:48 web.1     | {
12:49:48 web.1     |   "error": "redirect_uri_mismatch",
12:49:48 web.1     |   "error_description": "Redirect URI mismatch."
12:49:48 web.1     | }
12:49:48 web.1     | Processing by OmniauthCallbacksController#failure as HTML
12:49:48 web.1     |   Parameters: {"code"=>"123", "state"=>"456", "username"=>"kevin@kpsoftware.io"}
12:49:48 web.1     | Redirected to http://localhost:5000/credentials
12:49:48 web.1     | Completed 302 Found in 1ms (ActiveRecord: 0.0ms | Allocations: 294)

I found a very old support article where someone had the same issue. However, their solution description is a bit cryptic. https://community.constantcontact.com/t5/Developer-Support-ask-questions/Redirect-URI-mismatch-Access-Token-Request/m-p/98467

borovyi commented 2 years ago

@kpheasey I got the same issue. You just need to redefine callback_url - https://github.com/omniauth/omniauth-oauth2/issues/93#issuecomment-227247801 In my case it looks like this:

# omniauth.rb

module OmniAuthExtensions
  def callback_url
    full_host + script_name + callback_path
  end
end

OmniAuth::Strategies::ConstantContact2.include OmniAuthExtensions