redirect_mismatch (again)

Sorry, i dig all what i have found here and on google but can’t fix my bug.

This is the URI registered for my application on my twitch account:

http://mydomain.com/vsfederation_site/index.php?page=account&action=twitch_connect

this is my connection string

https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=[mycode]&redirect_uri=http://mydomain.com/vsfederation_site/index.php?page=account&action=twitch_connect&scope=user_read

the URI are exactly the same, as you can see and as i copypasted it into the account, but what i get is:

Array
(
[page] => account
[action] => twitch_connect
[error] => redirect_mismatch
[error_description] => Parameter redirect_uri does not match registered URI
)

could anybody kindly help?

After a quick looks it appears you are not escaping the redirect url before the redirect back to Twitch (mainly the query string).

This should work:

https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=[mycode]&redirect_uri=http%3A%2F%2Fmydomain.com%2Fvsfederation_site%2Findex.php%3Fpage%3Daccount%26action%3Dtwitch_connect&scope=user_read
1 Like

Make sure to url encode the redirect_uri. http://mydomain.com/vsfederation_site/index.php?page=account&action=twitch_connect becomes http%3A%2F%2Fmydomain.com%2Fvsfederation_site%2Findex.php%3Fpage%3Daccount%26action%3Dtwitch_connect, so the final url will be https://api.twitch.tv/kraken/oauth2/authorize?response_type=token&client_id=[mycode]&redirect_uri=http%3A%2F%2Fmydomain.com%2Fvsfederation_site%2Findex.php%3Fpage%3Daccount%26action%3Dtwitch_connect&scope=user_read.

2 Likes

it works :slight_smile:
then there are so many tricks, but i past my code where i authenticate, then rethreive the token, then load user data.
The kink:

		<p><a href="https://api.twitch.tv/kraken/oauth2/authorize?response_type=code&client_id=agagagagagagagqcg&redirect_uri=http%3A%2F%2Fmydomain.com%2Fvsfederation_site%2Findex.php%3Fpage%3Daccount%26action%3Dtwitch_connect&scope=user_read" class="btn btn-slide-panel btn-lg btn-block" >link</a></p>

The code to get linkback parameters (php)

$url = 'https://api.twitch.tv/kraken/oauth2/token';
$fields = array(
				'client_id' => urlencode('agagagagagagag4vak49ekqcg'),
				'client_secret' => urlencode('agagagagagagagagagiczy3g1kejq4zlwqt'),
				'grant_type' => urlencode('authorization_code'),
				'redirect_uri' => 'http%3A%2F%2Fmydomain.com%2Fvsfederation_site%2Findex.php%3Fpage%3Daccount%26action%3Dtwitch_connect',
				'code' => urlencode($_REQUEST['code'])
				);
$fields_string ="";
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
$array = get_object_vars(json_decode($result));
$access_token = $array['access_token'];
$scope = "user_read";

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "https://api.twitch.tv/kraken/user");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$headers = array();
$headers[] = "Accept: application/vnd.twitchtv.v3+json";
$headers[] = "Authorization: OAuth ".$access_token."";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$content = curl_exec($ch);
curl_close($ch);
$array = get_object_vars(json_decode($content));
	
	} else {
	die("nein");
	}

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