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
crtest1crtest1 

Using Partner WSDL API with OAuth?

Hi,

 

I'm using Partner WSDL API v21. I need to connect to SFDC for various SFDC users, and i think using username/password is not the best way to obtan SFDC connection through Partner WSDL API. I'm wondering if I can use OAuth in this case. By far I can get SFDC users' instance_url, client_id, client_secret and refresh_token. What I like to use OAuth in this scenario is send a request to user's instance_url to get a refreshed access token, and use the latest access token to access user's resources.

 

Would it work in this way by using Partner WSDL API wih OAuth? If so, can you post some sample codes?

 

Thanks,

Michael

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

You'd use the refresh_token with the token service to get a new access_token, see the oauth docs & samples.

All Answers

SuperfellSuperfell

Yes, you can use an oauth access_token in the soap apis (by putting where the sessionId would normally go in the SessionHeader)

crtest1crtest1

That's great.

 

Do you mean insert access_token to SessionHeader?Can you post some sample codes for it? It will give me a better understanding.

 

Thanks,

Michael

SuperfellSuperfell

instead of 

 

sh.setSessionId(loginResult.getSessionId())

 

you'd have

sh.setSessionId(oauth.getAccessToken());

crtest1crtest1

Thanks a lot for your help.

 

I have one last question which would be important to me. As i mentioned above, by far I can get SFDC users' instance_url, client_id, client_secret and refresh_token. How can I use the API as well to call SFDC with all these information to get access_token? I mean how to get to the point of 'oauth.getAccessToken()'. It'll be appreciated if you can post the sample codes too for getting 'oauth' result.

 

Thanks,

Michael

SuperfellSuperfell

You'd use the refresh_token with the token service to get a new access_token, see the oauth docs & samples.

This was selected as the best answer