I tried the answer at "Can the redirect_uri contain port number"?

But I am getting the following error:

Provided redirect_uri does not match the redirect_uri this code was created with

My access log looks like:

::1 - - [14/Mar/2019:22:49:31 CST] "GET /auth/stackexchange/callback?code=umZowLeAHg*z6Gs*(yIBUg))&state=7a24d06c83edd66415483ce0b32d1bd8714b730215a30e9c HTTP/1.1" 302 9http://localhost:3000/ -> /auth/stackexchange/callback?code=umZowLeAHg*z6Gs(yIBUg))&state=7a24d06c83edd66415483ce0b32d1bd8714b730215a30e9c

Started GET "/auth/failure?message=invalid_credentials&origin=http%3A%2F%2Flocalhost%3A3000%2Fusers%2Fabbc%2Fedit&strategy=stackexchange" for ::1 at 2019-03-14 22:49:50 +0800

::1 - - [14/Mar/2019:22:49:50 CST] "GET /auth/failure?message=invalid_credentials&origin=http%3A%2F%2Flocalhost%3A3000%2Fusers%2Fabbc%2Fedit&strategy=stackexchange HTTP/1.1" 301 88http://localhost:3000/ -> /auth/failuremessage=invalid_credentials&origin=http%3A%2F%2Flocalhost%3A3000%2Fusers%2Fabbc%2Fedit&strategy=stackexchange

I used Rails and my code is like this:

gem 'omniauth', '~> 1.9'
gem 'omniauth-oauth2', '~> 1.6'
gem 'omniauth-stackexchange', '~> 0.2.1'

# initializers/omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :stackexchange, Rails.application.secrets.stack_client_id, Rails.application.secrets.stack_client_secret, public_key: Rails.application.secrets.stack_key, site: 'stackoverflow',callback_url:'http://localhost:3000/'

My Stack Apps application settings are like this:

  • OAuth Domain: localhost
  • Application Website: http://localhost:3000/
  • Stack Apps Post: Not set
  • Client Side Flow: Disabled
  • Desktop OAuth Redirect Uri: Disabled

These are screenshots of the settings on the app's page:

enter image description here

enter image description here

How do I fix this?

  • I'm not a Ruby expert, but that doesn't look like how others use omniauth-stackexchange. See this other Q&A for example. Commented Mar 14, 2019 at 19:11

1 Answer 1


I get the reason:

Do not use gem 'omniauth-stackexchange', '~> 0.2.1' ,but instead of gem 'omniauth-stackexchange', git: 'https://github.com/nashby/omniauth-stackexchange.git'

The reason see this:add call back url

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .