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

Commit 84f7eae

Browse files
babolivierrichvdh
authored andcommitted
Improve the UX of the login fallback when using SSO (#7152)
* Don't show the login forms if we're currently logging in with a password or a token. * Submit directly the SSO login form, showing only a spinner to the user, in order to eliminate from the clunkiness of SSO through this fallback.
1 parent fb69690 commit 84f7eae

3 files changed

Lines changed: 32 additions & 22 deletions

File tree

changelog.d/7152.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve the support for SSO authentication on the login fallback page.

synapse/static/client/login/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<body onload="matrixLogin.onLoad()">
1010
<center>
1111
<br/>
12-
<h1>Log in with one of the following methods</h1>
12+
<h1 id="title"></h1>
1313

1414
<span id="feedback" style="color: #f00"></span>
1515

synapse/static/client/login/js/login.js

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
window.matrixLogin = {
22
endpoint: location.origin + "/_matrix/client/r0/login",
33
serverAcceptsPassword: false,
4-
serverAcceptsCas: false,
54
serverAcceptsSso: false,
65
};
76

7+
var title_pre_auth = "Log in with one of the following methods";
8+
var title_post_auth = "Logging in...";
9+
810
var submitPassword = function(user, pwd) {
911
console.log("Logging in with password...");
12+
set_title(title_post_auth);
1013
var data = {
1114
type: "m.login.password",
1215
user: user,
1316
password: pwd,
1417
};
1518
$.post(matrixLogin.endpoint, JSON.stringify(data), function(response) {
16-
show_login();
1719
matrixLogin.onLogin(response);
1820
}).error(errorFunc);
1921
};
2022

2123
var submitToken = function(loginToken) {
2224
console.log("Logging in with login token...");
25+
set_title(title_post_auth);
2326
var data = {
2427
type: "m.login.token",
2528
token: loginToken
2629
};
2730
$.post(matrixLogin.endpoint, JSON.stringify(data), function(response) {
28-
show_login();
2931
matrixLogin.onLogin(response);
3032
}).error(errorFunc);
3133
};
3234

3335
var errorFunc = function(err) {
34-
show_login();
36+
// We want to show the error to the user rather than redirecting immediately to the
37+
// SSO portal (if SSO is the only login option), so we inhibit the redirect.
38+
show_login(true);
3539

3640
if (err.responseJSON && err.responseJSON.error) {
3741
setFeedbackString(err.responseJSON.error + " (" + err.responseJSON.errcode + ")");
@@ -45,26 +49,33 @@ var setFeedbackString = function(text) {
4549
$("#feedback").text(text);
4650
};
4751

48-
var show_login = function() {
49-
$("#loading").hide();
50-
52+
var show_login = function(inhibit_redirect) {
5153
var this_page = window.location.origin + window.location.pathname;
5254
$("#sso_redirect_url").val(this_page);
5355

54-
if (matrixLogin.serverAcceptsPassword) {
55-
$("#password_flow").show();
56+
// If inhibit_redirect is false, and SSO is the only supported login method, we can
57+
// redirect straight to the SSO page
58+
if (matrixLogin.serverAcceptsSso) {
59+
if (!inhibit_redirect && !matrixLogin.serverAcceptsPassword) {
60+
$("#sso_form").submit();
61+
return;
62+
}
63+
64+
// Otherwise, show the SSO form
65+
$("#sso_form").show();
5666
}
5767

58-
if (matrixLogin.serverAcceptsSso) {
59-
$("#sso_flow").show();
60-
} else if (matrixLogin.serverAcceptsCas) {
61-
$("#sso_form").attr("action", "/_matrix/client/r0/login/cas/redirect");
62-
$("#sso_flow").show();
68+
if (matrixLogin.serverAcceptsPassword) {
69+
$("#password_flow").show();
6370
}
6471

65-
if (!matrixLogin.serverAcceptsPassword && !matrixLogin.serverAcceptsCas && !matrixLogin.serverAcceptsSso) {
72+
if (!matrixLogin.serverAcceptsPassword && !matrixLogin.serverAcceptsSso) {
6673
$("#no_login_types").show();
6774
}
75+
76+
set_title(title_pre_auth);
77+
78+
$("#loading").hide();
6879
};
6980

7081
var show_spinner = function() {
@@ -74,17 +85,15 @@ var show_spinner = function() {
7485
$("#loading").show();
7586
};
7687

88+
var set_title = function(title) {
89+
$("#title").text(title);
90+
};
7791

7892
var fetch_info = function(cb) {
7993
$.get(matrixLogin.endpoint, function(response) {
8094
var serverAcceptsPassword = false;
81-
var serverAcceptsCas = false;
8295
for (var i=0; i<response.flows.length; i++) {
8396
var flow = response.flows[i];
84-
if ("m.login.cas" === flow.type) {
85-
matrixLogin.serverAcceptsCas = true;
86-
console.log("Server accepts CAS");
87-
}
8897
if ("m.login.sso" === flow.type) {
8998
matrixLogin.serverAcceptsSso = true;
9099
console.log("Server accepts SSO");
@@ -102,7 +111,7 @@ var fetch_info = function(cb) {
102111
matrixLogin.onLoad = function() {
103112
fetch_info(function() {
104113
if (!try_token()) {
105-
show_login();
114+
show_login(false);
106115
}
107116
});
108117
};

0 commit comments

Comments
 (0)