• licheng
  • NEWBIE
  • 25 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies

Hi, all

    Followed with "http://www.salesforce.com/us/developer/docs/api_rest/Content/quickstart_oauth.htm", I'm trying to make a simple client test code to pass. Unfortunately, I could get the authorization token, but when could not get access token, and the response I got when requiring access token is :

 {"error":"invalid_grant","error_description":"invalid authorization code"}.

 

Following is my test code

step1: Registry one remote app, and get customer_key and customer_secret

        customer key: 3MVG9Y6d_Btp4xp4S0UExFwosGGJCLQZq3k8mUbBu6DoVNiWVlxqKMHCzpPi4DHx9b.PsxqacuY5hwpGFlxCM

        customer secret: 7497167051685992293

step2: Open browser, access following url, which includes the required parameters, as below

       https://login.salesforce.com/services/oauth2/authorize?response_type=code&redirect_uri=https%3A%2F%2...

Step3: Get authorization token from the browser address bar

  https://10.111.3.82:8443/?code=aPrxaSyVmC8fBbeBsvplbPnf.sN3TAsh8c2Dnrrxbd203sy7T1m8WbTWtknf_EqNJEZDh...

 

Step4: Try to get access token with following code:
        HttpClient client = new HttpClient();
        PostMethod post = new PostMethod("https://login.salesforce.com/services/oauth2/token");
        post.setParameter("grant_type","authorization_code");
        post.setParameter("client_id","3MVG9Y6d_Btp4xp4S0UExFwosGGJCLQZq3k8mUbBu6DoVNiWVlxqKMHCzpPi4DHx9b.PsxqacuY5hwpGFlxCM");
        post.setParameter("client_secret","7497167051685992293");
        post.setParameter("redirect_uri","https://10.111.3.82:8443");
        post.setParameter("code", "aPrxaSyVmC8fBbeBsvplbPnf.sN3TAsh8c2Dnrrxbd203sy7T1m8WbTWtknf_EqNJEZDh3DYIQ%3D%3D");
        post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        client.executeMethod(post);
        String responseBody = post.getResponseBodyAsString();
        String accessToken = null;
        JSONObject json = null;
        try {
            json = new JSONObject(responseBody);
            accessToken = json.getString("access_token");
        } catch (JSONException e) {
             e.printStackTrace();
        }

 

 Unfortunately, I always get responseBody as below

{"error":"invalid_grant","error_description":"invalid authorization code"}

 

Please help!

Hi, all

    Followed with "http://www.salesforce.com/us/developer/docs/api_rest/Content/quickstart_oauth.htm", I'm trying to make a simple client test code to pass. Unfortunately, I could get the authorization token, but when could not get access token, and the response I got when requiring access token is :

 {"error":"invalid_grant","error_description":"invalid authorization code"}.

 

Following is my test code

step1: Registry one remote app, and get customer_key and customer_secret

        customer key: 3MVG9Y6d_Btp4xp4S0UExFwosGGJCLQZq3k8mUbBu6DoVNiWVlxqKMHCzpPi4DHx9b.PsxqacuY5hwpGFlxCM

        customer secret: 7497167051685992293

step2: Open browser, access following url, which includes the required parameters, as below

       https://login.salesforce.com/services/oauth2/authorize?response_type=code&redirect_uri=https%3A%2F%2F10.111.3.82%3A8443&client_id=3MVG9Y6d_Btp4xp4S0UExFwosGGJCLQZq3k8mUbBu6DoVNiWVlxqKMHCzpPi4DHx9b.PsxqacuY5hwpGFlxCM

Step3: Get authorization token from the browser address bar

  https://10.111.3.82:8443/?code=aPrxaSyVmC8fBbeBsvplbPnf.sN3TAsh8c2Dnrrxbd203sy7T1m8WbTWtknf_EqNJEZDh3DYIQ%3D%3D

 

Step4: Try to get access token with following code:
        HttpClient client = new HttpClient();
        PostMethod post = new PostMethod("https://login.salesforce.com/services/oauth2/token");
        post.setParameter("grant_type","authorization_code");
        post.setParameter("client_id","3MVG9Y6d_Btp4xp4S0UExFwosGGJCLQZq3k8mUbBu6DoVNiWVlxqKMHCzpPi4DHx9b.PsxqacuY5hwpGFlxCM");
        post.setParameter("client_secret","7497167051685992293");
        post.setParameter("redirect_uri","https://10.111.3.82:8443");
        post.setParameter("code", "aPrxaSyVmC8fBbeBsvplbPnf.sN3TAsh8c2Dnrrxbd203sy7T1m8WbTWtknf_EqNJEZDh3DYIQ%3D%3D");
        post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        client.executeMethod(post);
        String responseBody = post.getResponseBodyAsString();
        String accessToken = null;
        JSONObject json = null;
        try {
            json = new JSONObject(responseBody);
            accessToken = json.getString("access_token");
        } catch (JSONException e) {
             e.printStackTrace();
        }

 

 Unfortunately, I always get responseBody as below

{"error":"invalid_grant","error_description":"invalid authorization code"}

 

Please help!

Hi, all

    Followed with "http://www.salesforce.com/us/developer/docs/api_rest/Content/quickstart_oauth.htm", I'm trying to make a simple client test code to pass. Unfortunately, I could get the authorization token, but when could not get access token, and the response I got when requiring access token is :

 {"error":"invalid_grant","error_description":"invalid authorization code"}.

 

Following is my test code

step1: Registry one remote app, and get customer_key and customer_secret

        customer key: 3MVG9Y6d_Btp4xp4S0UExFwosGGJCLQZq3k8mUbBu6DoVNiWVlxqKMHCzpPi4DHx9b.PsxqacuY5hwpGFlxCM

        customer secret: 7497167051685992293

step2: Open browser, access following url, which includes the required parameters, as below

       https://login.salesforce.com/services/oauth2/authorize?response_type=code&redirect_uri=https%3A%2F%2...

Step3: Get authorization token from the browser address bar

  https://10.111.3.82:8443/?code=aPrxaSyVmC8fBbeBsvplbPnf.sN3TAsh8c2Dnrrxbd203sy7T1m8WbTWtknf_EqNJEZDh...

 

Step4: Try to get access token with following code:
        HttpClient client = new HttpClient();
        PostMethod post = new PostMethod("https://login.salesforce.com/services/oauth2/token");
        post.setParameter("grant_type","authorization_code");
        post.setParameter("client_id","3MVG9Y6d_Btp4xp4S0UExFwosGGJCLQZq3k8mUbBu6DoVNiWVlxqKMHCzpPi4DHx9b.PsxqacuY5hwpGFlxCM");
        post.setParameter("client_secret","7497167051685992293");
        post.setParameter("redirect_uri","https://10.111.3.82:8443");
        post.setParameter("code", "aPrxaSyVmC8fBbeBsvplbPnf.sN3TAsh8c2Dnrrxbd203sy7T1m8WbTWtknf_EqNJEZDh3DYIQ%3D%3D");
        post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        client.executeMethod(post);
        String responseBody = post.getResponseBodyAsString();
        String accessToken = null;
        JSONObject json = null;
        try {
            json = new JSONObject(responseBody);
            accessToken = json.getString("access_token");
        } catch (JSONException e) {
             e.printStackTrace();
        }

 

 Unfortunately, I always get responseBody as below

{"error":"invalid_grant","error_description":"invalid authorization code"}

 

Please help!

I'm following this tutorial:

https://na6.salesforce.com/help/doc/en/remoteaccess_oauth_web_server_flow.htm

 

When I get to the final step - requesting the auth token - I always get an undocumented "unsupported_grant_type" message. Seems like this is some kind of generic error message, but I can't get around it.

 

I correctly retrieve a code form the initial GET request. Fine.

I generate a POST using that code:

 

POST /services/oauth2/token HTTP/1.0 Host: login.salesforce.com User-Agent: Drupal (+http://drupal.org/) Content-Length: 300 grant_type=authorization_code&code=aPrxVyeZrusRBnc3MMnY7pNlQsARBRDqXQTQ12UzEIDjUBJjlgXOq4_IUp.9E3k%3D&client_id=XXXXXXXXXXXXX&client_secret=XXXXXXXXXXXXX&redirect_uri=https%3A%2F%2Flocalhost%2FRestTest%2Fsalesforce%2Foauth

 

And the response is always the same:

 

{"error":"unsupported_grant_type","error_description":"grant type not supported"}

 

Everything is properly url encoded, and I've followed the directions to a T.

Any ideas?