def authenticate(self):
        # if another thread is in this method, wait for it to finish.
        # always release the lock no matter what happens in the block
        db_alias = self.db_alias
        if not db_alias in connections:
            raise KeyError("authenticate function signature has been changed. "
                    "The db_alias parameter more important than settings_dict")
        with oauth_lock:
            if not db_alias in oauth_data:
                settings_dict = self.settings_dict
                if settings_dict['USER'] == 'dynamic auth':
                    oauth_data[db_alias] = {'instance_url': settings_dict['HOST']}
                else:
                    url = ''.join([settings_dict['HOST'], '/services/oauth2/token'])

                    log.info("attempting authentication to %s" % settings_dict['HOST'])
                    self._session.mount(settings_dict['HOST'], SslHttpAdapter(max_retries=MAX_RETRIES))
                    response = self._session.post(url, data=dict(
                        grant_type      = 'password',
                        client_id       = settings_dict['CONSUMER_KEY'],
                        client_secret   = settings_dict['CONSUMER_SECRET'],
                        username        = settings_dict['USER'],
                        password        = settings_dict['PASSWORD'],
                    ))
                    if response.status_code == 200:
                        response_data = response.json()
                        calc_signature = (base64.b64encode(hmac.new(
                                key=settings_dict['CONSUMER_SECRET'].encode('ascii'),
                                msg=(response_data['id'] + response_data['issued_at']).encode('ascii'),
                                digestmod=hashlib.sha256).digest())).decode('ascii')
                        if calc_signature == response_data['signature']:
                            log.info("successfully authenticated %s" % settings_dict['USER'])
                            oauth_data[db_alias] = response_data
                        else:
                            raise RuntimeError('Invalid auth signature received')
                    else:
                        raise LookupError("oauth failed: %s: %s" % (settings_dict['USER'], response.text))

            return oauth_data[db_alias]
Authenticate to the Salesforce API with the provided credentials.
dataset/ETHPy150Open django-salesforce/django-salesforce/salesforce/auth.py/SalesforceAuth.authenticate