Skip to content

2.2.0

Latest

Choose a tag to compare

@caffalaughrey caffalaughrey released this 21 Mar 16:55
· 1 commit to master since this release
326e6cf

This release introduces support for OAuth2 Device Flow.

Example implementation

import SalesforcePy as sfdc
import json

def on_authorize(res, authz):
    # Add any required logic to perform on authorization response here
    pass

def on_authenticate(res, authn):
    # Raise an exception if the response was any error other than pending authorization, otherwise return.
    if authn.status != 200 and authn.exceptions[0].get("error") != "authorization_pending":
        raise Exception(json.dumps(res))
    else:
        return

client = sfdc.client(None, None, "<client id here>")

# Note that `on_authorize` and `on_authenticate` handlers are optional but highly recommended, especially
# to ensure authn polling fails out appropriately.
with client.login_via_device_flow(on_authorize=on_authorize, on_authenticate=on_authenticate) as c:
    account = c.query('SELECT Id FROM Account LIMIT 1')