| 257 | self.port = 0 |
| 258 | |
| 259 | def launch_browser(self, tool_name): |
| 260 | user_html = """<html> |
| 261 | <form id="auth" action="http://127.0.0.1:{PORT}/login/{PAGE_NAME}" method="POST"> |
| 262 | <input type="hidden" name="token" value="{TOKEN}"> |
| 263 | </form> |
| 264 | <script type="text/javascript"> |
| 265 | document.getElementById("auth").submit(); |
| 266 | </script> |
| 267 | </html>""".format(PORT=self.port, PAGE_NAME=tool_name, TOKEN=self.access_token) |
| 268 | # use a local html file to send access token to our service via http POST for authentication. |
| 269 | os.makedirs(localdata_dir, exist_ok=True) |
| 270 | filename = os.path.join(localdata_dir, "launch_{}.html".format(tool_name)) |
| 271 | with open(filename, "w") as f: |
| 272 | f.write(user_html) |
| 273 | os.startfile(filename) |
| 274 | |
| 275 | def run(self, tool_name): |
| 276 | # find a port number that's available |