Skip to content

Instantly share code, notes, and snippets.

@truth3
Created June 16, 2016 18:05
Show Gist options
  • Select an option

  • Save truth3/255ea4c4c3bd9db73a1d9f027186bcc1 to your computer and use it in GitHub Desktop.

Select an option

Save truth3/255ea4c4c3bd9db73a1d9f027186bcc1 to your computer and use it in GitHub Desktop.

Revisions

  1. truth3 created this gist Jun 16, 2016.
    28 changes: 28 additions & 0 deletions iFormBuilder-API-AccessToken(Python).py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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