From 90f22c7b43d14c848052e62543d61e3775ccc29f Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 15 Nov 2018 19:05:39 +0000 Subject: [PATCH] Support for m.login.sso Adds support for the m.login.sso login type, which is handled the same way as CAS, and also makes it look a bit nicer. --- res/css/structures/login/_Login.scss | 11 +++++++ src/Login.js | 8 ++--- src/components/structures/login/Login.js | 14 ++++----- src/components/views/login/CasLogin.js | 38 ------------------------ src/i18n/strings/en_EN.json | 2 +- 5 files changed, 21 insertions(+), 52 deletions(-) delete mode 100644 src/components/views/login/CasLogin.js diff --git a/res/css/structures/login/_Login.scss b/res/css/structures/login/_Login.scss index 84b8306a74..1264d2a30f 100644 --- a/res/css/structures/login/_Login.scss +++ b/res/css/structures/login/_Login.scss @@ -142,6 +142,17 @@ limitations under the License. color: $primary-fg-color; } +.mx_Login_sso_link { + display: block; + text-align: center; + font-size: 15px; + margin-bottom: 20px; +} + +.mx_Login_sso_link:link { + color: $primary-fg-color; +} + .mx_Login_loader { display: inline; position: relative; diff --git a/src/Login.js b/src/Login.js index 61a14959d8..ec55a1e8c7 100644 --- a/src/Login.js +++ b/src/Login.js @@ -16,7 +16,6 @@ limitations under the License. */ import Matrix from "matrix-js-sdk"; -import { _t } from "./languageHandler"; import Promise from 'bluebird'; import url from 'url'; @@ -225,19 +224,18 @@ export default class Login { }); } - redirectToCas() { + getSsoLoginUrl(loginType) { const client = this._createTemporaryClient(); const parsedUrl = url.parse(window.location.href, true); // XXX: at this point, the fragment will always be #/login, which is no // use to anyone. Ideally, we would get the intended fragment from // MatrixChat.screenAfterLogin so that you could follow #/room links etc - // through a CAS login. + // through an SSO login. parsedUrl.hash = ""; parsedUrl.query["homeserver"] = client.getHomeserverUrl(); parsedUrl.query["identityServer"] = client.getIdentityServerUrl(); - const casUrl = client.getCasLoginUrl(url.format(parsedUrl)); - window.location.href = casUrl; + return client.getSsoLoginUrl(url.format(parsedUrl), loginType); } } diff --git a/src/components/structures/login/Login.js b/src/components/structures/login/Login.js index 45f523f141..92cddb0dc1 100644 --- a/src/components/structures/login/Login.js +++ b/src/components/structures/login/Login.js @@ -84,7 +84,10 @@ module.exports = React.createClass({ // letting you do that login type this._stepRendererMap = { 'm.login.password': this._renderPasswordStep, - 'm.login.cas': this._renderCasStep, + + // CAS and SSO are the same thing, modulo the url we link to + 'm.login.cas': () => this._renderSsoStep(this._loginLogic.getSsoLoginUrl("cas")), + 'm.login.sso': () => this._renderSsoStep(this._loginLogic.getSsoLoginUrl("sso")), }; this._initLoginLogic(); @@ -186,10 +189,6 @@ module.exports = React.createClass({ }).done(); }, - onCasLogin: function() { - this._loginLogic.redirectToCas(); - }, - _onLoginAsGuestClick: function() { const self = this; self.setState({ @@ -403,10 +402,9 @@ module.exports = React.createClass({ ); }, - _renderCasStep: function() { - const CasLogin = sdk.getComponent('login.CasLogin'); + _renderSsoStep: function(url) { return ( - + { _t('Sign in with single sign-on') } ); }, diff --git a/src/components/views/login/CasLogin.js b/src/components/views/login/CasLogin.js deleted file mode 100644 index 9219c79733..0000000000 --- a/src/components/views/login/CasLogin.js +++ /dev/null @@ -1,38 +0,0 @@ -/* -Copyright 2015, 2016 OpenMarket Ltd - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -'use strict'; - -import React from 'react'; -import PropTypes from 'prop-types'; -import { _t } from '../../../languageHandler'; - -module.exports = React.createClass({ - displayName: 'CasLogin', - - propTypes: { - onSubmit: PropTypes.func, // fn() - }, - - render: function() { - return ( -
- -
- ); - }, - -}); diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 572cc0d2b3..1ae379404c 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -638,7 +638,6 @@ "Message removed": "Message removed", "Robot check is currently unavailable on desktop - please use a web browser": "Robot check is currently unavailable on desktop - please use a web browser", "This Home Server would like to make sure you are not a robot": "This Home Server would like to make sure you are not a robot", - "Sign in with CAS": "Sign in with CAS", "Custom Server Options": "Custom Server Options", "You can use the custom server options to sign into other Matrix servers by specifying a different Home server URL.": "You can use the custom server options to sign into other Matrix servers by specifying a different Home server URL.", "This allows you to use this app with an existing Matrix account on a different home server.": "This allows you to use this app with an existing Matrix account on a different home server.", @@ -1218,6 +1217,7 @@ "Error: Problem communicating with the given homeserver.": "Error: Problem communicating with the given homeserver.", "Can't connect to homeserver via HTTP when an HTTPS URL is in your browser bar. Either use HTTPS or enable unsafe scripts.": "Can't connect to homeserver via HTTP when an HTTPS URL is in your browser bar. Either use HTTPS or enable unsafe scripts.", "Can't connect to homeserver - please check your connectivity, ensure your homeserver's SSL certificate is trusted, and that a browser extension is not blocking requests.": "Can't connect to homeserver - please check your connectivity, ensure your homeserver's SSL certificate is trusted, and that a browser extension is not blocking requests.", + "Sign in with single sign-on": "Sign in with single sign-on", "Try the app first": "Try the app first", "Sign in to get started": "Sign in to get started", "Failed to fetch avatar URL": "Failed to fetch avatar URL",