Problems with my Redirect URI using rails

Sorry for this being a fairly basic question, but I can’t figure this out for the life of me.

I’m building a simple rails app, trying to use the Twitch OAuth to log in users.
My routes are simple:
> get “/auth/twitch”, as: :twitch_login

    get "/auth/twitch/callback", to: "sessions#create"

So, hypothetically my redirect_uri should be as simple as:

http://localhost:3000/auth/twitch/callback

I’ve tried this in all configurations I can think of using localhost, 127.0.0.1, with and without the port…

Each time I end up with this error:

OAuth2::Error
Bad Request: {“error”:“Bad Request”,“status”:400,“message”:“Parameter redirect_uri does not match registered URI”}

Any idea on what simple thing I’m missing?

The redirect URL you provided for your registered app under https://www.twitch.tv/settings/connections does not match with what you provided as a callback. They have to be 100% identical.

So, I’m using http://127.0.0.1:3000/auth/twitch/callback as the address, and I literally copied and pasted “http://127.0.0.1:3000/auth/twitch/callback” into the redirect field on that form.

Try making your request from the page you defined as a registered URI?

Just tried that - no luck.

I’m using the OAuth-Twitch gem, is that changing the response I get?

What is rails passing in as the redirect_uri to Twitch when it calls the API? Maybe that is getting corrupted or is not what you think it is? Assuming you are still having the redirect error.

I’m really not sure how to check that…

Are you sure that when you hit save, chrome/browser didn’t accidentally wack a / on the end as a auto complete measure. I’ve had that happen and it’s caught me out once of twice.

But recheck ALL your settings, to make sure you got all the right keys/clientID etc

A Google for “OAuth-Twitch gem” returns Three results with the same name but different authors. Which are you using?

So - it appears to work now, and I’m not exactly sure why.
I think the final fix was specifying this in my gemfile:

gem ‘omniauth-twitch’, git: ‘git://github.com/WebTheoryLLC/omniauth-twitch.git’

Oddly, that didn’t seem to change anything. I then altered the route slightly and it worked perfectly. I was then able to alter the route BACK to what it was, and it still works.

I think I may not have restarted my server in between those steps, and I’m assuming that specifying the gem was the key here. (I was trying to be diligent about restarting the server whenever I made a change, but I can’t be positive I did right after that step).

Thanks for the help everyone!

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.