Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

share|improve this question
5  
One thing to be wary of here is the values are cached for a short about of time too, which means if you're constantly changing it trying to work out what's wrong, you're probably shooting yourself in the foot. I've done it before, and more than once! –  LaceySnr Feb 6 '13 at 22:08
    
Deleted the troubleshooting discussion and posted the solution as an answer. –  metadaddy Feb 6 '13 at 23:39
4  
@LaceySnr The propagation delay across the login service has been the cause of much swearing! –  metadaddy Feb 6 '13 at 23:41
1  
@metadaddy it has, I've seen the threads to back that up. –  ehime Feb 6 '13 at 23:43
add comment

2 Answers 2

up vote 5 down vote accepted

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);
share|improve this answer
add comment

I'd just like to bring it to peoples attention that it's

redirect_uri

and not

redirect_url

It's given in the Chatter REST API documentation as the second incorrect one - I just spent a few hours on this issue :|

share|improve this answer
1  
Filing a doc bug right now. Thanks! –  metadaddy Mar 27 at 15:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.