5

I implemented the OAuth integration with my external app. Created a Remote Access(Connected App) configuration with a callback url (https://mysite.com/oauthcallback). Here I received the call back with a "code=xyz...". I made a http post with the following params to https:/login.salesforce.com/services/oauth2/token

"code":code
"grant_type", "authorization_code"
"client_id", "XYZ..."
"client_secret", "123..."
"redirect_uri", "https:/mysite.com/oauthcallback"

for which I received the following response from sfdc

"issued_at": "1375365820732",
 "scope": "refresh_token",
 "access_token": "00Dabc..!ABC...",
 "refresh_token": "abc...",
 "signature": "XYZ..."

I use the refresh token and fetch the access token or for time being use the access_token I get here for the following REST API https:/naxx.salesforce.com/services/data/v28.0/sobjects/Account/accountId and set the header as Authorization: Bearer

This returns me invalid session ID. Also tried the following options Authorization: OAuth X_SFDC_Session:

The Remote access(Connected App) has the access for "Refresh_Token", "API", Full Access" :) I end up with the same error. Can someone help me on this.

2
  • The specific error that I am receiving is --"message": "This session is not valid for use with the REST API", "errorCode": "INVALID_SESSION_ID"
    – Sundar
    Aug 1, 2013 at 15:11
  • post some code.
    – superfell
    Aug 1, 2013 at 23:06

2 Answers 2

2

http://help.salesforce.com/apex/HTViewHelpDoc?id=connected_app_create.htm&language=en_US

reading this awesome article from sfdc its very clearly mentioned that " full does not return a refresh token. You must explicitly request the refresh_token scope to get a refresh token".

hence a refresh_token access is also needed .

3
  • Hi @mohith , I did follow these steps and got the refresh token successfully. In the scope I have added refresh token also as I mentioned along with full access and api access. With the refresh token I was able to get the access token too. But when i use it with a rest api it throw invalid session I'd error.
    – Sundar
    Aug 1, 2013 at 20:55
  • I'm following the steps similar to what is explained in this link wiki.developerforce.com/page/… . esp the sections that talks about making a SOQL rest api call, that is where I am getting the error.
    – Sundar
    Aug 1, 2013 at 21:09
  • post the code you are using to call api from sfdc? Aug 2, 2013 at 1:13
2

I found the problem, basically the call that I was making for authorize was as following https://login.salesforce.com/services/oauth2/authorize?response_type=code&scope=refresh_token&client_id=&display=popup&redirect_uri=https://mysite.com/oauthcallback

In the above url you can see that I mentioned the scope=refresh_token, this restricted the scope of the authorization and the refresh_token(and subsequently access_token) I receive does not have permission to access the Rest API's

Solution:- Specify scope=refresh_token,api,full access or just remove the parameter, it will pick up the all the scope from remote access (Connected app).

Thanks for your help Mohit!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .