'Get a Requests session with the headers needed to properly authenticate it with
the SAP SuccessFactors OData API.'

def get_odata_api_client(self, user_id):

    session = requests.Session()
    assertion = session.post(self.sapsf_idp_url, data={'client_id': self.odata_client_id, 'user_id': user_id, 'token_url': self.sapsf_token_url, 'private_key': self.sapsf_private_key}, timeout=self.timeout)
    assertion.raise_for_status()
    assertion = assertion.text
    token = session.post(self.sapsf_token_url, data={'client_id': self.odata_client_id, 'company_id': self.odata_company_id, 'grant_type': 'urn:ietf:params:oauth:grant-type:saml2-bearer', 'assertion': assertion}, timeout=self.timeout)
    token.raise_for_status()
    token = token.json()['access_token']
    session.headers.update({'Authorization': 'Bearer    {}'.format(token), 'Accept': 'application/json'})
    return session
