From c3097979f282e03da512326f9f5dd69ad46f9e7e Mon Sep 17 00:00:00 2001 From: Steven Hammerton Date: Thu, 5 Nov 2015 15:19:04 +0000 Subject: [PATCH] Change login with CAS to redirect to HS for CAS login --- lib/client.js | 26 +++++--------------------- lib/http-api.js | 9 +++++++++ 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/lib/client.js b/lib/client.js index 5d11df353..685e3d8ca 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1722,28 +1722,12 @@ MatrixClient.prototype.loginWithSAML2 = function(relayState, callback) { }; /** - * @param {module:client.callback} callback Optional. - * @return {module:client.Promise} Resolves: TODO - * @return {module:http-api.MatrixError} Rejects: with an error response. + * @param {string} redirectUrl URL to which to be redirect to after + * HS authenticates with CAS and issues login token + * Will redirect to homeserver to complete CAS login */ -MatrixClient.prototype.getCasServer = function(callback) { - return this._http.request( - callback, "GET", "/login/cas", undefined, undefined - ); -}; - -/** - * @param {string} ticket (Received from CAS) - * @param {string} service Service to which the token was granted - * @param {module:client.callback} callback Optional. - * @return {module:client.Promise} Resolves: TODO - * @return {module:http-api.MatrixError} Rejects: with an error response. - */ -MatrixClient.prototype.loginWithCas = function(ticket, service, callback) { - return this.login("m.login.cas", { - ticket: ticket, - service: service - }, callback); +MatrixClient.prototype.loginWithCas = function(redirectUrl) { + this._http.redirect("/login/cas/redirect", {"redirectUrl": redirectUrl}, httpApi.PREFIX_V1); }; /** diff --git a/lib/http-api.js b/lib/http-api.js index 09b3d4d38..03c498691 100644 --- a/lib/http-api.js +++ b/lib/http-api.js @@ -296,6 +296,15 @@ module.exports.MatrixHttpApi.prototype = { return this._request(callback, method, fullUri, queryParams, data); }, + redirect: function(path, queryParams, prefix) { + var queryString = ""; + if (queryParams) { + queryString = "?" + utils.encodeParams(queryParams); + } + var fullUri = this.opts.baseUrl + prefix + path + queryString; + window.location.href = fullUri; + }, + _request: function(callback, method, uri, queryParams, data) { if (callback !== undefined && !utils.isFunction(callback)) { throw Error(