Skip to content

Instantly share code, notes, and snippets.

@truth3
Created June 16, 2016 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save truth3/255ea4c4c3bd9db73a1d9f027186bcc1 to your computer and use it in GitHub Desktop.
Save truth3/255ea4c4c3bd9db73a1d9f027186bcc1 to your computer and use it in GitHub Desktop.
CREATE JWT AND ACCESS TOKEN USING PYTHON LIBRARY'S
import jwt, base64, os, uuid, sys, urllib, urllib2, json, collections, traceback, time, datetime
from datetime import timedelta
#############################################################################
get an jwt then make call to get access token ##
#############################################################################
def GetAccessToken(iFormUrl, iFormClientKey, iFormClientSecret):
expTime = datetime.datetime.utcnow() + datetime.timedelta(seconds=600)
nowTime = datetime.datetime.utcnow()
payload = {"iss": iFormClientKey,
"aud": iFormUrl + "/exzact/api/oauth/token",
"exp": expTime,
"iat": nowTime}
encoded = jwt.encode(payload, iFormClientSecret, algorithm='HS256')
#print encoded
tokenData = { 'grant_type': 'urn:ietf:params:oauth:grant-type:jwt-bearer',
'assertion': encoded
}
tokenResponse = urllib2.urlopen(iFormUrl + '/exzact/api/oauth/token', urllib.urlencode(tokenData))
responseString = tokenResponse.read()
#print "responseString is: " + responseString
json_acceptable_string = responseString.replace("'", "\"")
responseDictionary = json.loads(json_acceptable_string)
#for key, value in responseDictionary.iteritems() :
#print key, value
token = responseDictionary.get("access_token", "none")
print "the token is: " + token
return token
@truth3
Copy link
Author

truth3 commented Jun 16, 2016

@Jedeii
Copy link

Jedeii commented Aug 24, 2016

every time i try and request a token it is giving me error 405 the only thing i have changed is

expTime = int(time.time()) + 600
nowTime = int(time.time())

other then that everything is the same, I know I am passing the function the correct data I just cant figure out why its refusing me!!
Any help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment