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

Commit

Permalink
Support m.login.sso (#4220)
Browse files Browse the repository at this point in the history
* Clean up the CSS for the fallback login form

I was finding this hard to work with, so simplify a bunch of things. Each
flow is now a form inside a div of class login_flow.

The login_flow class now has a fixed width, as that looks much better than each
flow having a differnt width.

* Support m.login.sso

MSC1721 renames m.login.cas to m.login.sso. This implements the change
(retaining support for m.login.cas for older clients).

* changelog
  • Loading branch information
richvdh authored and hawkowl committed Nov 27, 2018
1 parent a44c0a0 commit 944d524
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 52 deletions.
1 change: 1 addition & 0 deletions changelog.d/4220.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rename login type m.login.cas to m.login.sso
13 changes: 9 additions & 4 deletions synapse/rest/client/v1/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from synapse.api.errors import Codes, LoginError, SynapseError
from synapse.http.server import finish_request
from synapse.http.servlet import parse_json_object_from_request
from synapse.http.servlet import RestServlet, parse_json_object_from_request
from synapse.types import UserID
from synapse.util.msisdn import phone_number_to_msisdn

Expand Down Expand Up @@ -83,6 +83,7 @@ class LoginRestServlet(ClientV1RestServlet):
PATTERNS = client_path_patterns("/login$")
SAML2_TYPE = "m.login.saml2"
CAS_TYPE = "m.login.cas"
SSO_TYPE = "m.login.sso"
TOKEN_TYPE = "m.login.token"
JWT_TYPE = "m.login.jwt"

Expand All @@ -105,6 +106,10 @@ def on_GET(self, request):
if self.saml2_enabled:
flows.append({"type": LoginRestServlet.SAML2_TYPE})
if self.cas_enabled:
flows.append({"type": LoginRestServlet.SSO_TYPE})

# we advertise CAS for backwards compat, though MSC1721 renamed it
# to SSO.
flows.append({"type": LoginRestServlet.CAS_TYPE})

# While its valid for us to advertise this login type generally,
Expand Down Expand Up @@ -384,11 +389,11 @@ def on_POST(self, request):
defer.returnValue((200, {"status": "not_authenticated"}))


class CasRedirectServlet(ClientV1RestServlet):
PATTERNS = client_path_patterns("/login/cas/redirect", releases=())
class CasRedirectServlet(RestServlet):
PATTERNS = client_path_patterns("/login/(cas|sso)/redirect")

def __init__(self, hs):
super(CasRedirectServlet, self).__init__(hs)
super(CasRedirectServlet, self).__init__()
self.cas_server_url = hs.config.cas_server_url.encode('ascii')
self.cas_service_url = hs.config.cas_service_url.encode('ascii')

Expand Down
37 changes: 16 additions & 21 deletions synapse/static/client/login/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,30 @@
<h1>Log in with one of the following methods</h1>

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

<div id="loading">
<img src="spinner.gif" />
</div>

<div id="cas_flow" class="login_flow" style="display:none"
onclick="gotoCas(); return false;">
CAS Authentication: <button id="cas_button" style="margin: 10px">Log in</button>
<div id="sso_flow" class="login_flow" style="display:none">
Single-sign on:
<form id="sso_form" action="/_matrix/client/r0/login/sso/redirect" method="get">
<input id="sso_redirect_url" type="hidden" name="redirectUrl" value=""/>
<input type="submit" value="Log in"/>
</form>
</div>

<br/>

<form id="password_form" class="login_flow" style="display:none"
onsubmit="matrixLogin.password_login(); return false;">
<div>
Password Authentication:<br/>

<div style="text-align: center">
<input id="user_id" size="32" type="text" placeholder="Matrix ID (e.g. bob)" autocapitalize="off" autocorrect="off" />
<br/>
<input id="password" size="32" type="password" placeholder="Password"/>
<br/>
<div id="password_flow" class="login_flow" style="display:none">
Password Authentication:
<form onsubmit="matrixLogin.password_login(); return false;">
<input id="user_id" size="32" type="text" placeholder="Matrix ID (e.g. bob)" autocapitalize="off" autocorrect="off" />
<br/>
<input id="password" size="32" type="password" placeholder="Password"/>
<br/>

<button type="submit" style="margin: 10px">Log in</button>
</div>
</div>
</form>
<input type="submit" value="Log in"/>
</form>
</div>

<div id="no_login_types" type="button" class="login_flow" style="display:none">
Log in currently unavailable.
Expand Down
32 changes: 18 additions & 14 deletions synapse/static/client/login/js/login.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
window.matrixLogin = {
endpoint: location.origin + "/_matrix/client/api/v1/login",
endpoint: location.origin + "/_matrix/client/r0/login",
serverAcceptsPassword: false,
serverAcceptsCas: false
serverAcceptsCas: false,
serverAcceptsSso: false,
};

var submitPassword = function(user, pwd) {
Expand Down Expand Up @@ -40,25 +41,25 @@ var errorFunc = function(err) {
}
};

var gotoCas = function() {
var this_page = window.location.origin + window.location.pathname;
var redirect_url = matrixLogin.endpoint + "/cas/redirect?redirectUrl=" + encodeURIComponent(this_page);
window.location.replace(redirect_url);
}

var setFeedbackString = function(text) {
$("#feedback").text(text);
};

var show_login = function() {
$("#loading").hide();

var this_page = window.location.origin + window.location.pathname;
$("#sso_redirect_url").val(encodeURIComponent(this_page));

if (matrixLogin.serverAcceptsPassword) {
$("#password_form").show();
$("#password_flow").show();
}

if (matrixLogin.serverAcceptsCas) {
$("#cas_flow").show();
if (matrixLogin.serverAcceptsSso) {
$("#sso_flow").show();
} else if (matrixLogin.serverAcceptsCas) {
$("#sso_form").attr("action", "/_matrix/client/r0/login/cas/redirect");
$("#sso_flow").show();
}

if (!matrixLogin.serverAcceptsPassword && !matrixLogin.serverAcceptsCas) {
Expand All @@ -67,8 +68,8 @@ var show_login = function() {
};

var show_spinner = function() {
$("#password_form").hide();
$("#cas_flow").hide();
$("#password_flow").hide();
$("#sso_flow").hide();
$("#no_login_types").hide();
$("#loading").show();
};
Expand All @@ -84,7 +85,10 @@ var fetch_info = function(cb) {
matrixLogin.serverAcceptsCas = true;
console.log("Server accepts CAS");
}

if ("m.login.sso" === flow.type) {
matrixLogin.serverAcceptsSso = true;
console.log("Server accepts SSO");
}
if ("m.login.password" === flow.type) {
matrixLogin.serverAcceptsPassword = true;
console.log("Server accepts password");
Expand Down
19 changes: 6 additions & 13 deletions synapse/static/client/login/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,23 @@ a:hover { color: #000; }
a:active { color: #000; }

input {
width: 90%
}

textarea, input {
font-family: inherit;
font-size: inherit;
margin: 5px;
}

.smallPrint {
color: #888;
font-size: 9pt ! important;
font-style: italic ! important;
textbox, input[type="text"], input[type="password"] {
width: 90%;
}

.g-recaptcha div {
margin: auto;
form {
text-align: center;
margin: 10px 0 0 0;
}

.login_flow {
width: 300px;
text-align: left;
padding: 10px;
margin-bottom: 40px;
display: inline-block;

-webkit-border-radius: 10px;
-moz-border-radius: 10px;
Expand Down

0 comments on commit 944d524

Please sign in to comment.