Token validation and various cleanup
This commit is contained in:
@@ -5,67 +5,11 @@ import threading
|
||||
from logbook import Logger
|
||||
import socketserver
|
||||
import json
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
# noinspection PyPep8
|
||||
HTML = '''
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
|
||||
<title>pyfa Local Server</title>
|
||||
<style type="text/css">
|
||||
body {{ text-align: center; padding: 150px; }}
|
||||
h1 {{ font-size: 40px; }}
|
||||
h2 {{ font-size: 32px; }}
|
||||
body {{ font: 20px Helvetica, sans-serif; color: #333; }}
|
||||
#article {{ display: block; text-align: left; width: 650px; margin: 0 auto; }}
|
||||
a {{ color: #dc8100; text-decoration: none; }}
|
||||
a:hover {{ color: #333; text-decoration: none; }}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- Layout from Short Circuit's CREST login. Shout out! https://github.com/farshield/shortcircuit -->
|
||||
<div id="article">
|
||||
<h1>pyfa</h1>
|
||||
{0}
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
function extractFromHash(name, hash) {{
|
||||
var match = hash.match(new RegExp(name + "=([^&]+)"));
|
||||
return !!match && match[1];
|
||||
}}
|
||||
|
||||
var hash = window.location.hash;
|
||||
var token = extractFromHash("access_token", hash);
|
||||
var step2 = extractFromHash("step2", hash);
|
||||
|
||||
function doRedirect() {{
|
||||
if (token){{
|
||||
// implicit authentication
|
||||
var redirect = window.location.origin.concat('/?', window.location.hash.substr(1), '&step=2');
|
||||
window.location = redirect;
|
||||
}}
|
||||
else {{
|
||||
// user-defined
|
||||
var redirect = window.location.href + '&step=2';
|
||||
window.location = redirect;
|
||||
}}
|
||||
}}
|
||||
|
||||
// do redirect if we are not already on step 2
|
||||
if (window.location.href.indexOf('step=2') == -1) {{
|
||||
setTimeout(doRedirect(), 1000);
|
||||
}}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
'''
|
||||
|
||||
class SSOError(Exception):
|
||||
pass
|
||||
|
||||
# https://github.com/fuzzysteve/CREST-Market-Downloader/
|
||||
class AuthHandler(http.server.BaseHTTPRequestHandler):
|
||||
@@ -86,16 +30,26 @@ class AuthHandler(http.server.BaseHTTPRequestHandler):
|
||||
pyfalog.info("Successfully logged into EVE.")
|
||||
is_success = True
|
||||
self.send_response(200)
|
||||
self.send_header('Access-Control-Allow-Origin', '*')
|
||||
self.end_headers()
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
raise
|
||||
except SSOError as ex:
|
||||
pyfalog.error("Error logging into EVE")
|
||||
pyfalog.error(ex)
|
||||
self.send_response(500)
|
||||
self.send_header('Access-Control-Allow-Origin', '*')
|
||||
self.end_headers()
|
||||
self.wfile.write(str.encode(str(ex)))
|
||||
except Exception as ex:
|
||||
pyfalog.error("Error logging into EVE")
|
||||
pyfalog.error(ex)
|
||||
self.send_response(500)
|
||||
# send error
|
||||
finally:
|
||||
self.send_header('Access-Control-Allow-Origin', '*')
|
||||
self.end_headers()
|
||||
# send error
|
||||
|
||||
|
||||
|
||||
if is_success:
|
||||
self.server.stop()
|
||||
|
||||
Reference in New Issue
Block a user