Example #1
0
def authenticate(request):
    if request.POST.get('json_data') is not None:
        #get body of keys sent by OneID signing process
        var = StringIO()
        var.write(request.POST.get('json_data', {}))
        body_of_the_request = simplejson.loads(var.getvalue())

        #Get API_ID and API_KEY from OneID
        jsonurl = urlopen("https://keychain.oneid.com/register")
        parsed_JSON_keys = json.loads(jsonurl.read())

        #Validate the obtained body with OneID service using the provided keys.
        body = body_of_the_request
        print body
        oneid_data = body
        oneid_connector = OneID(parsed_JSON_keys['API_ID'], parsed_JSON_keys['API_KEY'])
        valid = oneid_connector.validate(oneid_data)
        if oneid_connector.success(valid):
            #initiate session
            print "session will be initiated with UserId: " + body_of_the_request["uid"]
            request.session["uid"] = body_of_the_request["uid"]
            return True
        else:
            return False
    else:
        return False
Example #2
0
#!/usr/bin/python

from oneid import OneID
import sys
import urllib
try:
    import json
except ImportError:
    import simplejson as json

print """Content-Type: text/html
"""

authn = OneID()

authn.set_credentials()

line = sys.stdin.readline()

resp = authn.validate(line)

sessionid = authn.save_session(resp)

print authn.redirect('account.py', resp, sessionid)