CREATE JWT AND ACCESS TOKEN USING PYTHON LIBRARY'S
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 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 |
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
Code sample for this example:
https://iformbuilder.zendesk.com/hc/en-us/community/posts/202919374-Get-a-JWT-and-Access-Token-using-Python-Library-s