Show a shorter URL to open for SSO

Show "http://127.0.0.1:port", which will automatically redirect to the
long ugly homeserver's URL.
This commit is contained in:
miruka 2020-07-26 20:40:55 -04:00
parent 157ea2ffb2
commit ddee50f28a

View File

@ -44,16 +44,25 @@ _SUCCESS_HTML_PAGE = """<!DOCTYPE html>
class _SSORequestHandler(BaseHTTPRequestHandler): class _SSORequestHandler(BaseHTTPRequestHandler):
def do_GET(self) -> None: def do_GET(self) -> None:
self.server: "SSOServer"
redirect = "%s/_matrix/client/r0/login/sso/redirect?redirectUrl=%s" % (
self.server.for_homeserver,
quote(self.server.url_to_open),
)
parameters = parse_qs(urlparse(self.path).query) parameters = parse_qs(urlparse(self.path).query)
if "loginToken" in parameters: if "loginToken" in parameters:
self.server._token = parameters["loginToken"][0] # type: ignore self.server._token = parameters["loginToken"][0]
self.send_response(200) self.send_response(200) # OK
self.send_header("Content-type", "text/html") self.send_header("Content-type", "text/html")
self.end_headers() self.end_headers()
self.wfile.write(_SUCCESS_HTML_PAGE.encode()) self.wfile.write(_SUCCESS_HTML_PAGE.encode())
else: else:
self.send_error(400, "missing loginToken parameter") self.send_response(308) # Permanent redirect, same method only
self.send_header("Location", redirect)
self.end_headers()
self.close_connection = True self.close_connection = True
@ -82,10 +91,7 @@ class SSOServer(HTTPServer):
def url_to_open(self) -> str: def url_to_open(self) -> str:
"""URL for the user to open in their browser, to do the SSO process.""" """URL for the user to open in their browser, to do the SSO process."""
return "%s/_matrix/client/r0/login/sso/redirect?redirectUrl=%s" % ( return f"http://{self.server_address[0]}:{self.server_port}"
self.for_homeserver,
quote(f"http://{self.server_address[0]}:{self.server_port}/"),
)
async def wait_for_token(self) -> str: async def wait_for_token(self) -> str: