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

Commit

Permalink
Accept a device ID to the login fallback endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Jun 3, 2020
1 parent 11dc2b4 commit 0d41ffc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
1 change: 1 addition & 0 deletions changelog.d/7629.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pass device information through to the login endpoint when using the login fallback.
60 changes: 31 additions & 29 deletions synapse/static/client/login/js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,19 @@ window.matrixLogin = {
var title_pre_auth = "Log in with one of the following methods";
var title_post_auth = "Logging in...";

var submitPassword = function(user, pwd) {
console.log("Logging in with password...");
var submitLogin = function(type, data) {
console.log("Logging in with " + type);
set_title(title_post_auth);
var data = {
type: "m.login.password",
user: user,
password: pwd,
};
$.post(matrixLogin.endpoint, JSON.stringify(data), function(response) {
matrixLogin.onLogin(response);
}).fail(errorFunc);
};

var submitToken = function(loginToken) {
console.log("Logging in with login token...");
set_title(title_post_auth);
var data = {
type: "m.login.token",
token: loginToken
};
// Add the login type.
data.type = type;

// Add the device ID, if one was provided.
var qs = parseQsFromUrl();
if (qs.device_id) {
data.device_id = qs.device_id;
}

$.post(matrixLogin.endpoint, JSON.stringify(data), function(response) {
matrixLogin.onLogin(response);
}).fail(errorFunc);
Expand All @@ -50,8 +43,9 @@ var setFeedbackString = function(text) {
};

var show_login = function(inhibit_redirect) {
var this_page = window.location.origin + window.location.pathname;
$("#sso_redirect_url").val(this_page);
// Set the redirect to come back to this page, a login token will get added
// and handled after the redirect.
$("#sso_redirect_url").val(window.location.href);

// If inhibit_redirect is false, and SSO is the only supported login method, we can
// redirect straight to the SSO page
Expand Down Expand Up @@ -123,15 +117,24 @@ matrixLogin.password_login = function() {
setFeedbackString("");

show_spinner();
submitPassword(user, pwd);
submitLogin("m.login.password", {user: user, password: pwd});
};

matrixLogin.onLogin = function(response) {
// clobber this function
console.warn("onLogin - This function should be replaced to proceed.");
};

var parseQsFromUrl = function(query) {
/*
* Process the query parameters from the current URL into an object.
*/
var parseQsFromUrl = function() {
var pos = window.location.href.indexOf("?");
if (pos == -1) {
return {};
}
var query = window.location.href.substr(pos + 1);

var result = {};
query.split("&").forEach(function(part) {
var item = part.split("=");
Expand All @@ -146,20 +149,19 @@ var parseQsFromUrl = function(query) {
return result;
};

/*
* Submits the login token if one is found in the query parameters. Returns a
* boolean of whether the login token was found or not.
*/
var try_token = function() {
var pos = window.location.href.indexOf("?");
if (pos == -1) {
return false;
}
var qs = parseQsFromUrl(window.location.href.substr(pos+1));
var qs = parseQsFromUrl();

var loginToken = qs.loginToken;

if (!loginToken) {
return false;
}

submitToken(loginToken);
submitLogin("m.login.token", {token: loginToken});

return true;
};

0 comments on commit 0d41ffc

Please sign in to comment.