From b963f177cc7422fdf7e710dd5ba2c5852ba9f04a Mon Sep 17 00:00:00 2001 From: Steven Hammerton Date: Fri, 6 Nov 2015 12:11:50 +0000 Subject: [PATCH] Update CAS login to return url rather than update location as the JS SDK may not be run within a browser env --- lib/client.js | 10 ++++++---- lib/http-api.js | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/client.js b/lib/client.js index 685e3d8ca..db2cc57a2 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1722,12 +1722,14 @@ MatrixClient.prototype.loginWithSAML2 = function(relayState, callback) { }; /** - * @param {string} redirectUrl URL to which to be redirect to after + * @param {string} redirectUrl URL to which to be redirected to after * HS authenticates with CAS and issues login token - * Will redirect to homeserver to complete CAS login + * @return {string} CAS login URL */ -MatrixClient.prototype.loginWithCas = function(redirectUrl) { - this._http.redirect("/login/cas/redirect", {"redirectUrl": redirectUrl}, httpApi.PREFIX_V1); +MatrixClient.prototype.getCasLoginUrl = function(redirectUrl) { + return this._http.getUrl("/login/cas/redirect", { + "redirectUrl": redirectUrl + }, httpApi.PREFIX_V1); }; /** diff --git a/lib/http-api.js b/lib/http-api.js index 03c498691..797daa426 100644 --- a/lib/http-api.js +++ b/lib/http-api.js @@ -296,13 +296,23 @@ module.exports.MatrixHttpApi.prototype = { return this._request(callback, method, fullUri, queryParams, data); }, - redirect: function(path, queryParams, prefix) { + /** + * Form and return a homeserver request URL based on the given path + * params and prefix. + * @param {string} path The HTTP path after the supplied prefix e.g. + * "/createRoom". + * @param {Object} queryParams A dict of query params (these will NOT be + * urlencoded). + * @param {string} prefix The full prefix to use e.g. + * "/_matrix/client/v2_alpha". + * @return {string} URL + */ + getUrl: function(path, queryParams, prefix) { var queryString = ""; if (queryParams) { queryString = "?" + utils.encodeParams(queryParams); } - var fullUri = this.opts.baseUrl + prefix + path + queryString; - window.location.href = fullUri; + return this.opts.baseUrl + prefix + path + queryString; }, _request: function(callback, method, uri, queryParams, data) {