Beispiel #1
0
def get_access_token(*, org_result, scratch_org_config):
    """Trades the AuthCode from a ScratchOrgInfo for an org access token,
    and stores it in the org config.

    The AuthCode is short-lived so this is only useful immediately after
    the scratch org is created. This must be completed once in order for future
    access tokens to be obtained using the JWT token flow.
    """
    oauth = SalesforceOAuth2(SF_CLIENT_ID, SF_CLIENT_SECRET, SF_CALLBACK_URL,
                             scratch_org_config.instance_url)
    auth_result = oauth.get_token(org_result["AuthCode"]).json()
    scratch_org_config.config[
        "access_token"] = scratch_org_config._scratch_info[
            "access_token"] = auth_result["access_token"]
Beispiel #2
0
 def refresh_oauth_token(self, connected_app):
     client_id = self.client_id
     client_secret = self.client_secret
     if not client_id:
         client_id = connected_app.client_id
         client_secret = connected_app.client_secret
     sf_oauth = SalesforceOAuth2(
         client_id,
         client_secret,
         connected_app.
         callback_url,  # Callback url isn't really used for this call
         auth_site=self.auth_site,
     )
     resp = sf_oauth.refresh_token(self.refresh_token).json()
     if resp != self.config:
         self.config.update(resp)
Beispiel #3
0
 def refresh_oauth_token(self, keychain, connected_app=None):
     if keychain: # it might be none'd and caller adds connected_app
         connected_app = keychain.get_service('connected_app')
     if connected_app is None:
         raise AttributeError('No connected app or keychain was passed to refresh_oauth_token.')
     client_id = self.client_id
     client_secret = self.client_secret
     if not client_id:
         client_id = connected_app.client_id
         client_secret = connected_app.client_secret
     sf_oauth = SalesforceOAuth2(
         client_id,
         client_secret,
         connected_app.callback_url,  # Callback url isn't really used for this call
         auth_site=self.instance_url,
     )
     resp = sf_oauth.refresh_token(self.refresh_token).json()
     if resp != self.config:
         self.config.update(resp)
     self._load_userinfo()
Beispiel #4
0
 def _create_oauth(self):
     return SalesforceOAuth2(
         client_id="foo_id",
         client_secret="foo_secret",
         callback_url="http://localhost:8080",
     )