forked from MirrorHub/synapse
Clean-up some auth/login REST code (#7115)
This commit is contained in:
parent
c165c1233b
commit
477c4f5b1c
3 changed files with 21 additions and 41 deletions
1
changelog.d/7115.misc
Normal file
1
changelog.d/7115.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
De-duplicate / remove unused REST code for login and auth.
|
|
@ -28,7 +28,6 @@ from synapse.http.servlet import (
|
||||||
parse_json_object_from_request,
|
parse_json_object_from_request,
|
||||||
parse_string,
|
parse_string,
|
||||||
)
|
)
|
||||||
from synapse.push.mailer import load_jinja2_templates
|
|
||||||
from synapse.rest.client.v2_alpha._base import client_patterns
|
from synapse.rest.client.v2_alpha._base import client_patterns
|
||||||
from synapse.rest.well_known import WellKnownBuilder
|
from synapse.rest.well_known import WellKnownBuilder
|
||||||
from synapse.types import UserID, map_username_to_mxid_localpart
|
from synapse.types import UserID, map_username_to_mxid_localpart
|
||||||
|
@ -548,13 +547,6 @@ class SSOAuthHandler(object):
|
||||||
self._registration_handler = hs.get_registration_handler()
|
self._registration_handler = hs.get_registration_handler()
|
||||||
self._macaroon_gen = hs.get_macaroon_generator()
|
self._macaroon_gen = hs.get_macaroon_generator()
|
||||||
|
|
||||||
# Load the redirect page HTML template
|
|
||||||
self._template = load_jinja2_templates(
|
|
||||||
hs.config.sso_redirect_confirm_template_dir, ["sso_redirect_confirm.html"],
|
|
||||||
)[0]
|
|
||||||
|
|
||||||
self._server_name = hs.config.server_name
|
|
||||||
|
|
||||||
# cast to tuple for use with str.startswith
|
# cast to tuple for use with str.startswith
|
||||||
self._whitelisted_sso_clients = tuple(hs.config.sso_client_whitelist)
|
self._whitelisted_sso_clients = tuple(hs.config.sso_client_whitelist)
|
||||||
|
|
||||||
|
|
|
@ -142,14 +142,6 @@ class AuthRestServlet(RestServlet):
|
||||||
% (CLIENT_API_PREFIX, LoginType.RECAPTCHA),
|
% (CLIENT_API_PREFIX, LoginType.RECAPTCHA),
|
||||||
"sitekey": self.hs.config.recaptcha_public_key,
|
"sitekey": self.hs.config.recaptcha_public_key,
|
||||||
}
|
}
|
||||||
html_bytes = html.encode("utf8")
|
|
||||||
request.setResponseCode(200)
|
|
||||||
request.setHeader(b"Content-Type", b"text/html; charset=utf-8")
|
|
||||||
request.setHeader(b"Content-Length", b"%d" % (len(html_bytes),))
|
|
||||||
|
|
||||||
request.write(html_bytes)
|
|
||||||
finish_request(request)
|
|
||||||
return None
|
|
||||||
elif stagetype == LoginType.TERMS:
|
elif stagetype == LoginType.TERMS:
|
||||||
html = TERMS_TEMPLATE % {
|
html = TERMS_TEMPLATE % {
|
||||||
"session": session,
|
"session": session,
|
||||||
|
@ -158,17 +150,19 @@ class AuthRestServlet(RestServlet):
|
||||||
"myurl": "%s/r0/auth/%s/fallback/web"
|
"myurl": "%s/r0/auth/%s/fallback/web"
|
||||||
% (CLIENT_API_PREFIX, LoginType.TERMS),
|
% (CLIENT_API_PREFIX, LoginType.TERMS),
|
||||||
}
|
}
|
||||||
html_bytes = html.encode("utf8")
|
|
||||||
request.setResponseCode(200)
|
|
||||||
request.setHeader(b"Content-Type", b"text/html; charset=utf-8")
|
|
||||||
request.setHeader(b"Content-Length", b"%d" % (len(html_bytes),))
|
|
||||||
|
|
||||||
request.write(html_bytes)
|
|
||||||
finish_request(request)
|
|
||||||
return None
|
|
||||||
else:
|
else:
|
||||||
raise SynapseError(404, "Unknown auth stage type")
|
raise SynapseError(404, "Unknown auth stage type")
|
||||||
|
|
||||||
|
# Render the HTML and return.
|
||||||
|
html_bytes = html.encode("utf8")
|
||||||
|
request.setResponseCode(200)
|
||||||
|
request.setHeader(b"Content-Type", b"text/html; charset=utf-8")
|
||||||
|
request.setHeader(b"Content-Length", b"%d" % (len(html_bytes),))
|
||||||
|
|
||||||
|
request.write(html_bytes)
|
||||||
|
finish_request(request)
|
||||||
|
return None
|
||||||
|
|
||||||
async def on_POST(self, request, stagetype):
|
async def on_POST(self, request, stagetype):
|
||||||
|
|
||||||
session = parse_string(request, "session")
|
session = parse_string(request, "session")
|
||||||
|
@ -196,15 +190,6 @@ class AuthRestServlet(RestServlet):
|
||||||
% (CLIENT_API_PREFIX, LoginType.RECAPTCHA),
|
% (CLIENT_API_PREFIX, LoginType.RECAPTCHA),
|
||||||
"sitekey": self.hs.config.recaptcha_public_key,
|
"sitekey": self.hs.config.recaptcha_public_key,
|
||||||
}
|
}
|
||||||
html_bytes = html.encode("utf8")
|
|
||||||
request.setResponseCode(200)
|
|
||||||
request.setHeader(b"Content-Type", b"text/html; charset=utf-8")
|
|
||||||
request.setHeader(b"Content-Length", b"%d" % (len(html_bytes),))
|
|
||||||
|
|
||||||
request.write(html_bytes)
|
|
||||||
finish_request(request)
|
|
||||||
|
|
||||||
return None
|
|
||||||
elif stagetype == LoginType.TERMS:
|
elif stagetype == LoginType.TERMS:
|
||||||
authdict = {"session": session}
|
authdict = {"session": session}
|
||||||
|
|
||||||
|
@ -225,17 +210,19 @@ class AuthRestServlet(RestServlet):
|
||||||
"myurl": "%s/r0/auth/%s/fallback/web"
|
"myurl": "%s/r0/auth/%s/fallback/web"
|
||||||
% (CLIENT_API_PREFIX, LoginType.TERMS),
|
% (CLIENT_API_PREFIX, LoginType.TERMS),
|
||||||
}
|
}
|
||||||
html_bytes = html.encode("utf8")
|
|
||||||
request.setResponseCode(200)
|
|
||||||
request.setHeader(b"Content-Type", b"text/html; charset=utf-8")
|
|
||||||
request.setHeader(b"Content-Length", b"%d" % (len(html_bytes),))
|
|
||||||
|
|
||||||
request.write(html_bytes)
|
|
||||||
finish_request(request)
|
|
||||||
return None
|
|
||||||
else:
|
else:
|
||||||
raise SynapseError(404, "Unknown auth stage type")
|
raise SynapseError(404, "Unknown auth stage type")
|
||||||
|
|
||||||
|
# Render the HTML and return.
|
||||||
|
html_bytes = html.encode("utf8")
|
||||||
|
request.setResponseCode(200)
|
||||||
|
request.setHeader(b"Content-Type", b"text/html; charset=utf-8")
|
||||||
|
request.setHeader(b"Content-Length", b"%d" % (len(html_bytes),))
|
||||||
|
|
||||||
|
request.write(html_bytes)
|
||||||
|
finish_request(request)
|
||||||
|
return None
|
||||||
|
|
||||||
def on_OPTIONS(self, _):
|
def on_OPTIONS(self, _):
|
||||||
return 200, {}
|
return 200, {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue