Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 822fd00

Browse files
committed
Use a template for the SSO success page to allow for customization.
1 parent 17a2433 commit 822fd00

6 files changed

Lines changed: 55 additions & 33 deletions

File tree

CHANGES.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
Next version
22
============
33

4-
* Two new templates (`sso_auth_confirm.html` and `sso_account_deactivated.html`)
5-
were added to Synapse. If your Synapse is configured to use SSO and a custom
6-
`sso_redirect_confirm_template_dir` configuration then these templates will
7-
need to be duplicated into that directory.
4+
* New templates (`sso_auth_confirm.html`, `sso_auth_success.html`, and
5+
`sso_account_deactivated.html`) were added to Synapse. If your Synapse is
6+
configured to use SSO and a custom `sso_redirect_confirm_template_dir`
7+
configuration then these templates will need to be duplicated into that
8+
directory.
89

910
* Plugins using the `complete_sso_login` method of `synapse.module_api.ModuleApi`
1011
should update to using the async/await version `complete_sso_login_async` which

changelog.d/7279.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support SSO in the user interactive authentication workflow.

synapse/config/sso.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ def read_config(self, config, **kwargs):
4343
),
4444
"sso_account_deactivated_template",
4545
)
46+
self.sso_auth_success_template = self.read_file(
47+
os.path.join(
48+
self.sso_redirect_confirm_template_dir, "sso_auth_success.html"
49+
),
50+
"sso_auth_success_template",
51+
)
4652

4753
self.sso_client_whitelist = sso_config.get("client_whitelist") or []
4854

synapse/handlers/auth.py

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,31 +53,6 @@
5353
logger = logging.getLogger(__name__)
5454

5555

56-
SUCCESS_TEMPLATE = """
57-
<html>
58-
<head>
59-
<title>Success!</title>
60-
<meta name='viewport' content='width=device-width, initial-scale=1,
61-
user-scalable=no, minimum-scale=1.0, maximum-scale=1.0'>
62-
<link rel="stylesheet" href="/_matrix/static/client/register/style.css">
63-
<script>
64-
if (window.onAuthDone) {
65-
window.onAuthDone();
66-
} else if (window.opener && window.opener.postMessage) {
67-
window.opener.postMessage("authDone", "*");
68-
}
69-
</script>
70-
</head>
71-
<body>
72-
<div>
73-
<p>Thank you</p>
74-
<p>You may now close this window and return to the application</p>
75-
</div>
76-
</body>
77-
</html>
78-
"""
79-
80-
8156
class AuthHandler(BaseHandler):
8257
SESSION_EXPIRE_MS = 48 * 60 * 60 * 1000
8358

@@ -161,6 +136,11 @@ def __init__(self, hs):
161136
self._sso_auth_confirm_template = load_jinja2_templates(
162137
hs.config.sso_redirect_confirm_template_dir, ["sso_auth_confirm.html"],
163138
)[0]
139+
# The following template is shown after a successful user interactive
140+
# authentication session. It tells the user they can close the window.
141+
self._sso_auth_success_template = hs.config.sso_auth_success_template
142+
# The following template is shown during the SSO authentication process if
143+
# the account is deactivated.
164144
self._sso_account_deactivated_template = (
165145
hs.config.sso_account_deactivated_template
166146
)
@@ -1091,12 +1071,12 @@ def complete_sso_ui_auth(
10911071
self._save_session(sess)
10921072

10931073
# Render the HTML and return.
1094-
html_bytes = SUCCESS_TEMPLATE.encode("utf8")
1074+
html = self._sso_auth_success_template.encode("utf-8")
10951075
request.setResponseCode(200)
10961076
request.setHeader(b"Content-Type", b"text/html; charset=utf-8")
1097-
request.setHeader(b"Content-Length", b"%d" % (len(html_bytes),))
1077+
request.setHeader(b"Content-Length", b"%d" % (len(html),))
10981078

1099-
request.write(html_bytes)
1079+
request.write(html)
11001080
finish_request(request)
11011081

11021082
async def complete_sso_login(
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<html>
2+
<head>
3+
<title>Authentication</title>
4+
</head>
5+
<body>
6+
<div>
7+
<p>Thank you</p>
8+
<p>You may now close this window and return to the application</p>
9+
</div>
10+
</body>
11+
</html>

synapse/rest/client/v2_alpha/auth.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from synapse.api.constants import LoginType
1919
from synapse.api.errors import SynapseError
2020
from synapse.api.urls import CLIENT_API_PREFIX
21-
from synapse.handlers.auth import SUCCESS_TEMPLATE
2221
from synapse.http.server import finish_request
2322
from synapse.http.servlet import RestServlet, parse_string
2423

@@ -90,6 +89,30 @@
9089
</html>
9190
"""
9291

92+
SUCCESS_TEMPLATE = """
93+
<html>
94+
<head>
95+
<title>Success!</title>
96+
<meta name='viewport' content='width=device-width, initial-scale=1,
97+
user-scalable=no, minimum-scale=1.0, maximum-scale=1.0'>
98+
<link rel="stylesheet" href="/_matrix/static/client/register/style.css">
99+
<script>
100+
if (window.onAuthDone) {
101+
window.onAuthDone();
102+
} else if (window.opener && window.opener.postMessage) {
103+
window.opener.postMessage("authDone", "*");
104+
}
105+
</script>
106+
</head>
107+
<body>
108+
<div>
109+
<p>Thank you</p>
110+
<p>You may now close this window and return to the application</p>
111+
</div>
112+
</body>
113+
</html>
114+
"""
115+
93116

94117
class AuthRestServlet(RestServlet):
95118
"""

0 commit comments

Comments
 (0)