-
-
Save Trudeaucj/09c25e79c332e93703a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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