diff --git a/java/standalone-servlet-example/src/main/java/com/janrain/example/AuthInfo.java b/java/standalone-servlet-example/src/main/java/com/janrain/example/AuthInfo.java index b013dc8..ff2ccd7 100644 --- a/java/standalone-servlet-example/src/main/java/com/janrain/example/AuthInfo.java +++ b/java/standalone-servlet-example/src/main/java/com/janrain/example/AuthInfo.java @@ -41,7 +41,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr writer.close(); // Here, we're just copying the response returned by the API to the page served to the browser. response.setCharacterEncoding("UTF-8"); - response.setContentType("text/javascript"); + response.setContentType("application/json"); IOUtils.copy(connection.getInputStream(), response.getOutputStream()); } diff --git a/python/rpxtokenurl.py b/python/rpxtokenurl.py index 3ed9f63..f63d835 100644 --- a/python/rpxtokenurl.py +++ b/python/rpxtokenurl.py @@ -1,10 +1,6 @@ # This code sample shows how to make the auth_info API call using Python. -import urllib -import urllib2 - -# json is native in python 2.6, but must be installed for previous versions -import json +import requests # Step 1) Extract the token from your environment. If you are using app engine, # you'd do something like: @@ -24,23 +20,25 @@ # Step 2) Now that we have the token, we need to make the api call to auth_info. # auth_info expects an HTTP Post with the following paramters: -api_params = { + +engage_api_params = { 'token': token, 'apiKey': 'REPLACE_WITH_YOUR_RPX_API_KEY', - 'format': 'json', + 'format': 'json' } +engage_api_url = 'https://rpxnow.com/api/v2/auth_info' + # make the api call -http_response = urllib2.urlopen('https://rpxnow.com/api/v2/auth_info', - urllib.urlencode(api_params)) -# read the json response -auth_info_json = http_response.read() +api_response = requests.get(engage_api_url, params=engage_api_params) # Step 3) process the json response -auth_info = json.loads(auth_info_json) + +auth_info = api_response.json() # Step 4) use the response to sign the user in + if auth_info['stat'] == 'ok': profile = auth_info['profile'] @@ -60,7 +58,4 @@ sign_in_user(identifier, name, email, profile_pic_url) else: - print 'An error occured: ' + auth_info['err']['msg'] - - - + print 'An error occured: ' + auth_info['err']['msg'] \ No newline at end of file