From e897c6c7f2316d90536aec1d0a1730d73894e216 Mon Sep 17 00:00:00 2001
From: Chris Hines <chris.hines@monash.edu>
Date: Fri, 12 Mar 2021 12:25:56 +1100
Subject: [PATCH] add an endpoint to set the cookie for transfering to a
 different client

---
 tes/apiendpoints.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/tes/apiendpoints.py b/tes/apiendpoints.py
index 8d27945..d46480a 100644
--- a/tes/apiendpoints.py
+++ b/tes/apiendpoints.py
@@ -434,6 +434,7 @@ class AppUrl(Resource):
             appdef = json.loads(request.args.get('app'))
             inst = json.loads(request.args.get('appinst'))
             inst['twsproxy']='{twsproxy}'
+            inst['twsproxyauth'] = request.cookies.get('twsproxyauth')
             url = "{}/{}".format("{twsproxy}",appdef['client']['redir'].format(**inst))
             return url
         except Exception as e:
@@ -443,6 +444,15 @@ class AppUrl(Resource):
             #flask_restful.abort(500,message="AppUrl failed in some unexpected way")
             return apiabort(500,message="AppUrl failed in some unexpected way")
 
+class SetTWSProxyAuth(Resource):
+    def get(self, authtok):
+        import urllib.parse
+        url = urllib.parse.unquote(request.args.get(redirect))
+        response = make_response(redirect(url))
+        response.set_cookie('twsproxyauth', authtok, secure=True)
+        return response
+
+
 class Ping(Resource):
     def get(self):
         return None, 201
@@ -564,6 +574,7 @@ api.add_resource(GetCert, '/getcert')
 api.add_resource(JobStat, '/stat')
 api.add_resource(Ping, '/ping')
 api.add_resource(JobCancel, '/cancel/<int:jobid>')
+api.add_resource(SetTWSProxyAuth, '/settwsproxyauth/<string:authtok>')
 api.add_resource(JobSubmit, '/submit')
 api.add_resource(CreateTunnel, '/createtunnel/<string:username>/<string:loginhost>/<string:batchhost>')
 api.add_resource(AppInstance, '/appinstance/<string:username>/<string:loginhost>/<string:batchhost>/<int:jobid>')
-- 
GitLab