Redirect_uri does not match registered URI

Hello All,
I am trying to add a Twitch OAuth to Yii2 which already has many others OAuth clients implemented.
I have read the doc about the authentication API found here https://github.com/justintv/Twitch-API/blob/master/authentication.md and many others posts related the same question as in the title.
Nothing helps. I still get the same error:

‘Request failed with code: 400, message: {“error”:“Bad Request”,“status”:400,“message”:“Parameter redirect_uri does not match registered URI”}’

Here are more details:
=== registered Redirect URI ===
http://www.my-domain.com/user/sign-in/oauth?authclient=twitch

=== Auth URL ===

https://api.twitch.tv/kraken/oauth2/authorize?client_id=[myclientId]&response_type=code&redirect_uri=http%3A%2F%2Fwww.my-domain.com%2Fuser%2Fsign-in%2Foauth%3Fauthclient%3Dtwitch&scope=user_read%20channel_read%20chat_login

For test purposes, after changing the registered Redirect URI to

http://www.my-domain.com/user/sign-in/oauth
and readapting the Auth URL, the error disappears.
So I wonder what is wrong in adding the authclient parameter to the registered redirect Uri.

Many thanks in advance for any help, tips or hints to sort this out.

I forgot to mention the url I am redirected to:

http://www.my-domain.com/user/sign-in/oauth?authclient=twitch&code=[codeabddddddddcode]&scope=user_read+channel_read+chat_login
despite the error.

Try using the state query string argument instead of using the authclient query string argument.

I myself use a query string argument on one of mine. But I do:

http://www.my-domain.com/user/sign-in/oauth/?authclient=twitch

Using your link as the example. Note the / on the end of the URL. URL’s are supposed/conventionally to end with a / and not be open ended like yours.

Thanks @BarryCarlyon for your reactivity.
Changed the redirect Url at both sides (twitch and App) like you suggested

http://www.my-domain.com/user/sign-in/oauth/?authclient=twitch

No luck. Got redirected to

http://www.my-domain.com/user/sign-in/oauth/?authclient=twitch&error=redirect_mismatch&error_description=Parameter+redirect_uri+does+not+match+registered+URI

Your OAuth redirect_uri must exactly match that of the one saved for your application in Twitch’s database. If you need to pass stateful information, you should do so through the state parameter.

I had a similar problem. It turned out that I had to be making my request from the page I defined as my registered URI…

I think the JS API checks:
window.location == redirect_uri

in order to verify that requests sent to the service are legit.

1 Like

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