Python Salesforce OAuth2client Helper
This library helps you use Google's oauth2client with Salesforce's oauth2 implementation.
Provided is a SalesforceOAuth2ServerFlow class as well as a patch to httplib2 to properly handle salesforce's authentication responses.
Works nearly the same as the built-in OAuth2ServerFlow. The only difference is that you must configure the salesforce instance first:
import sfoauth2 sfoauth2.SF_INSTANCE = 'na15'
Or manually pass in the auth and token uris to the constructor.
You can then create the authorization url as expected:
flow = sfoauth2.SalesforceOAuth2WebServerFlow( client_id=SF_CLIENT_ID, client_secret=SF_CLIENT_SECTION, scope=['api', 'refresh_token', 'full'] , redirect_uri='http://localhost/sfoauth2callback' ) authorization_url = flow.step1_get_authorize_url()
In your callback you can do the exchange as usual:
credentials = flow.step2_exchange(code)
At this point you can use the credentials to authorize an httplib2.Http instance to make requests:
http = httplib2.Http() credentials.authorize(http) r, c = http.request("https://na15.salesforce.com/services/data/v29.0/sobjects")
Apache Version 2.0