function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
gliderjockeygliderjockey 

Is OAuth 2.0 GA?

Hi,

 

I've been really struggling to get  OAuth 1.0 working with Salesforce so I've resorted to trying OAuth 2.0. I've followed the directions and even worked through some bugs and now Salesforce tells me that I am passing an invalid grant type. However I'm passing "access_token" as the value. I'm starting to believe that something is amiss with OAuth, or that it's not enabled for my org. Is there a way to tell? Do you only get OAuth 2.0 with REST?

 

Thanks for any help. I'm really stuck at this point.

 

Steve

SuperfellSuperfell

AFAIK, oAuth 2.0 is GA. I don't believe there is a grant type of access_token in oAuth2. I assume you've seen the online docs ? The REST Api webinar also included some peices on oAuth2 http://wiki.developerforce.com/index.php/Tech_Talk:_REST_API_Preview

gliderjockeygliderjockey

Simon,

 

Thanks for the response. After reading it, it triggered something and I realized I missed a step. Now I can do the dance and get an access token. Whoohoo!

 

But I'v run into another stumbling block. Now I'm trying to use the SOAP web service and am unsure how to pass the access token. The Web Services Developer's Guide is self referencing, as shown below:

 

"After a consumer using OAuth version 2.0 has an access token, the method of using the token depends on the API being
used.:
• For the SOAP API, the access token is placed in the Salesforce.com SOAP authentication header. See Web Services API
Developer's Guide."

 

I see instructions on how to do it using OAuth 1.0a, but can't find anything regarding the authentication header and OAuth 2.0. Any pointers?

 

Thanks,

 

Steve

SuperfellSuperfell

You'd put it in the sessionId field of the SessionHeader. (exactly the same place as if you'd called the soap login method instead of doing oAuth)

gliderjockeygliderjockey

Simon,

 

Thanks for the quick response. It's very much appreciated. I think I'm close, but not quite there.

 

I tried placing the access token in the session header, and receive the following errors when trying to invoke the getServerTimestamp() method.:

 

Exception: "Response is not well-formed XML."
Inner Exception: "Element 'Envelope' was not found. Line 1, position 2."

 

The code I'm using is:

 

    string token = Session["accessToken"].ToString();

    SforceService sf = new SforceService();
    sf.Url = "https://login.salesforce.com/services/OAuth/u/17.0";    //Tried 17.0, 19.0 and 20.0
    sf.Timeout = 60000;
    sf.SessionHeaderValue = new Partner.SessionHeader();
    sf.SessionHeaderValue.sessionId = token;
                
    GetServerTimestampResult result = sf.getServerTimestamp();

 

I'm have a web reference to the partner WSDL.

 

Thanks,

 

Steve

SuperfellSuperfell

You need to set the Url property correctly. e.g. https://na1.salesforce.com/services/Soap/u/17.0 the base instance URL is in the token response payload (and/or you can use the identity service to get the soap urls)

gliderjockeygliderjockey

Simon,

 

It worked! It occurred to me to try the NS3 server, but I forgot. I didn't realize that the instance server was returned with the token, even though I was capturing it.

 

For others who may be struggling through this, here is the code I use:

 

    string token = Session["accessToken"].ToString();
    string url = String.Format("{0}/services/Soap/u/17.0", Session["instanceURL"].ToString());

    SforceService sf = new SforceService();
    sf.Url = url;
    sf.Timeout = 60000;
    sf.SessionHeaderValue = new Partner.SessionHeader();
    sf.SessionHeaderValue.sessionId = token;

    GetServerTimestampResult result = sf.getServerTimestamp();

 

If I can get some time, I'll try to create a recipe for the whole OAuth 2.0 dance and add it to the cookbook.

 

Thanks again for your help,

 

Steve

maxlynchmaxlynch

Hi Simon,

 

I was having a similar problem but adding the proper url fixed it.  However, my url value is different from the one given here, it is actually this (I hope there is nothing sensitive in this URL):

 

https://na7-api.salesforce.com/services/Soap/u/20.0/MY_ID_HERE

 

However, I am getting my sessionid from OAuth which does not send this url.  How do I get it, or how do I use the identity services to get it?  I feel bad hardcoding the url above (which was obtained through a test of the login method with my username/password+token)

 

Thanks.

 

SuperfellSuperfell

One of the properties in the token response is the users identity URL (the property is called id i think). You can make a request to that URL to fetch details about the user, include the URL patterns for all the various APIs you might need. see the online help for the details https://na1.salesforce.com/help/doc/en/remoteaccess_using_openid.htm