Redirect Uri Mismatch when URI’s are the same

I’ve been dealing with this mismatch for the last two days, and am at my wits end. We have a development server set up (accessible from the outside), and I am trying to get my OAuth token back from my callback uri. I have my callback set up in my app as just how it is in our environmental configs.

The Config

And here is our attempt to reach the service, and the json response…

The URI callback attemp

Am I doing something wrong? or is there some configuration option I forgot in our app?

Here’s the Application setup…

App setup

Answer

It looks like the issue is in your call to retrieve the token. You should pass application/x-www-form-urlencoded data like so:

code=<code_you_just_received>&grant_type=authorization_code&client_id=<your_client_id>&client_secret=<your_client_secret>&redirect_uri=<your_redirect_uri>

There is a PHP sample in the Force.com Cookbook; the relevant code is

$token_url = LOGIN_URI . "/services/oauth2/token";

$code = $_GET['code'];

if (!isset($code) || $code == "") {
    die("Error - code parameter missing from request!");
}

$params = "code=" . $code
    . "&grant_type=authorization_code"
    . "&client_id=" . CLIENT_ID
    . "&client_secret=" . CLIENT_SECRET
    . "&redirect_uri=" . urlencode(REDIRECT_URI);

$curl = curl_init($token_url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);

$json_response = curl_exec($curl);

Attribution
Source : Link , Question Author : ehime , Answer Author : metadaddy

Leave a Comment