Search code examples
phpapilaravel-4twitch

Twitch API redirect_mismatch


I'm busy with the Twitch API since yesterday, had a simple authentication working, with redirect uri:

http://localhost:8000/redirect

Now i've changed the redirect uri to:

http://localhost:8000/connect/twitch

And it's not working anymore.

I've change the uri in the twitch app dashboard, and in the requests, but I still get the "Redirect_Mismatch".

What am I doing wrong?

Twitch Model:

class Twitch{

    var $client;
    var $oauth_token;

    public function __construct($token = null)
    {
        $this->client = new GuzzleHttp\Client();

        if($token != null) $this->setOAuthToken($token);
    }

    public function retrieveOAuthToken($code)
    {
        $res = $this->client->post('https://api.twitch.tv/kraken/oauth2/token', [
            'body' => [
                'client_id'     => Config::get('twitch.client_id'),
                'client_secret' => Config::get('twitch.client_secret'),
                'grant_type'    => 'authorization_code',
                'redirect_uri'  => Config::get('twitch.redirect_uri'),
                'code'          => $code
            ],
            'verify'            => false
        ]);

        $result = json_decode($res->getBody());
        $this->oauth_token = $result->access_token;
    }
}

Laravel Twitch Config file:

return array(

    'client_id' => 'REMOVED',

    'client_secret' => 'REMOVED',

    'redirect_uri' => 'http://localhost:8000/twitch',

);

Controller:

class ConnectController extends \BaseController {

    public function twitch()
    {
        $twitch = new Twitch();
        $twitch->retrieveOAuthToken(Input::get('code'));
    }
}

Twitch App Settings:

Twitch Settings


Solution

  • You need to update your laravel config:

    return array(
        'client_id' => 'REMOVED',
        'client_secret' => 'REMOVED',
        'redirect_uri' => 'http://localhost:8000/connect/twitch',
    );
    

    And you twitch redirect URI by http://localhost:8000/connect/twitch.

    If one one the 2 URLs (Laravel or Twitch settings) is different from the other, you will have the Redirect_Mismatch