Adjusted oauth test server and client to better reflect GED interface
authordurandn
Thu, 03 Mar 2016 16:28:46 +0100
changeset 10 50b532f5e6cb
parent 9 fdbc47f06361
child 11 cfc868991b82
Adjusted oauth test server and client to better reflect GED interface
oauth/client.py
oauth/oauth.py
--- a/oauth/client.py	Wed Mar 02 12:12:44 2016 +0100
+++ b/oauth/client.py	Thu Mar 03 16:28:46 2016 +0100
@@ -33,8 +33,10 @@
     if 'me' not in session:
         resp = remote.get('user/InfoComplete')
         print("authcode resp data: "+str(resp.data))
-        me = resp.data.get("username", "")
+        me = resp.data.get("displayName", "")
         session["me"] = me
+        id = resp.data.get("id", "")
+        session["me_id"] = id
     if 'remote_oauth_clientcredentials' not in session:
         auth_string = bytes(app.config["CLIENT_ID"]+':'+app.config['CLIENT_SECRET'], "utf-8")
         auth_code = base64.b64encode(auth_string).decode("utf-8")
@@ -51,17 +53,17 @@
         print("clientcredentials resp data: "+str(resp.data))
         server = resp.data.get("username", "")
         session["server"] = server
-    return render_template('client/index.html', current_username=session["me"], oauth_username=session["server"])
+    return render_template('client/index.html', current_user_id=session["me_id"], current_username=session["me"], oauth_username=session["server"])
 
 @app.route('/renkan-request')
 def renkan_request():
     if 'remote_oauth_clientcredentials' in session:
         resp = requests.post(
-            app.config["CREATE_RENKAN_ENDPOINT"]+"?act_as="+session.get("me", "anonymous"), 
+            app.config["CREATE_RENKAN_ENDPOINT"]+"?act_as="+str(session.get("me_id", "anonymous")), 
             {"title": "RENKAN_FROM_GED"},
             headers={
                 'Authorization': 'Bearer %s' % session['remote_oauth_clientcredentials'][0],
-                'renkan-act-as': session.get("me", "anonymous")
+                'renkan-act-as': session.get("me_id", "anonymous")
             }
         )
         print(resp.text)
--- a/oauth/oauth.py	Wed Mar 02 12:12:44 2016 +0100
+++ b/oauth/oauth.py	Thu Mar 03 16:28:46 2016 +0100
@@ -224,7 +224,7 @@
 @oauth.require_oauth()
 def user_info():
     user = request.oauth.user
-    return jsonify(id=user.id, username=user.username)
+    return jsonify(id=user.id, displayName=user.username)
 
 @app.route('/rest/oauth/validate/<token>')
 def validate_token(token):
@@ -238,14 +238,14 @@
         scope=database_token.scopes
     )
 
-@app.route('/ws/resource/<resource_id>', methods=["POST", "PUT"])
+@app.route('/ws/resource/', methods=["POST", "PUT"])
 @oauth.require_oauth()
-def reference_resource(resource_id):
+def reference_resource():
     print("#########################")
     print(request.headers)
     print("#########################")
     print(request.data)
-    return "Resource was referenced", 200
+    return "Request is valid", 200
 
 def init_client(client_id, client_secret, redirect_uris, client_owner, confidential=False):
     client = Client.query.filter_by(client_id=client_id, client_secret=client_secret).first()