Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import requests
import json
import base64
baseUrl = 'https://www.concursolutions.com'
oauthUrl = baseUrl+'/net2/oauth2/accesstoken.ashx'
reportDigestUrl = ''
def getbasic(user, password):
# basic authentication (according to HTTP)
return base64.encodestring(user + ":" + password)
def getTokenGivenUsernamePasswordAndConsumerKey(username, password, consumerKey):
"""
Given:
String username (Concur username)
String password (Concur password)
String ConsumerKey (Registered partner applciation consumerKey)
Example:
Python dictionary of the Oauth Response:
getTokenGivenUsernamePasswordAndConsumerKey('example@concur.com', '12345', 'ConsumerKey')
{u'Access_Token': {u'Expiration_date': u'5/7/2015 10:17:14 PM', u'Token': u'HERE IS A TOKEN',
u'Instance_Url': u'https://www.concursolutions.com/', u'Refresh_Token': u'HERE IS A REFRESH TOKEN'}}
You can then save this token and use it in the headers of your HTTP calls with the parameter:
Authorization: OAuth {Token}
"""
basic = 'Basic ' + getbasic(username, password)
headers1 = {'Authorization': basic.rstrip(), 'X-ConsumerKey': consumerKey, 'Accept':'application/json'}
r = requests.get(oauthUrl, headers=headers1)
return json.loads(r.content)
print getTokenGivenUsernamePasswordAndConsumerKey('ACCOUNT', 'PASSWORD', '<Insert Concur consumer key here>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.