Skip to content

Instantly share code, notes, and snippets.

@ismaelc
Created May 9, 2014 18:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ismaelc/9e3b9c3f0334d2b2c68a to your computer and use it in GitHub Desktop.
Save ismaelc/9e3b9c3f0334d2b2c68a to your computer and use it in GitHub Desktop.
Generate Concur access token in Python. You can find more details here https://developer.concur.com/api-documentation/oauth-20-0
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'NhYhZsP1zK1sARLHkWqSJpwfBIw=',
u'Instance_Url': u'https://www.concursolutions.com/', u'Refresh_Token': u's9Scoa2GdFkjQYFRgsXKrdcwJBrgIan'}}
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('user1@concurdisrupt.com', 'disrupt', '<Insert Concur consumer key here>')
def getListOfReports():
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment