Use server-generated deviceId

pull/21833/head
Richard van der Hoff 2016-08-11 14:21:52 +01:00
parent 5440fd7504
commit df22768f1b
4 changed files with 13 additions and 13 deletions

View File

@ -128,6 +128,7 @@ function _loginWithToken(queryParams) {
console.log("Logged in with token");
setLoggedIn({
userId: data.user_id,
deviceId: data.device_id,
accessToken: data.access_token,
homeserverUrl: queryParams.homeserver,
identityServerUrl: queryParams.identityServer,
@ -151,6 +152,7 @@ function _registerAsGuest(hsUrl, isUrl) {
console.log("Registered as guest: %s", creds.user_id);
setLoggedIn({
userId: creds.user_id,
deviceId: creds.device_id,
accessToken: creds.access_token,
homeserverUrl: hsUrl,
identityServerUrl: isUrl,
@ -170,6 +172,7 @@ function _restoreFromLocalStorage() {
const is_url = localStorage.getItem("mx_is_url") || 'https://matrix.org';
const access_token = localStorage.getItem("mx_access_token");
const user_id = localStorage.getItem("mx_user_id");
const device_id = localStorage.getItem("mx_device_id");
let is_guest;
if (localStorage.getItem("mx_is_guest") !== null) {
@ -183,6 +186,7 @@ function _restoreFromLocalStorage() {
console.log("Restoring session for %s", user_id);
setLoggedIn({
userId: user_id,
deviceId: device_id,
accessToken: access_token,
homeserverUrl: hs_url,
identityServerUrl: is_url,
@ -212,6 +216,7 @@ export function setLoggedIn(credentials) {
localStorage.setItem("mx_is_url", credentials.identityServerUrl);
localStorage.setItem("mx_user_id", credentials.userId);
localStorage.setItem("mx_device_id", credentials.deviceId);
localStorage.setItem("mx_access_token", credentials.accessToken);
localStorage.setItem("mx_is_guest", JSON.stringify(credentials.guest));
console.log("Session persisted for %s", credentials.userId);

View File

@ -21,21 +21,11 @@ import utils from 'matrix-js-sdk/lib/utils';
const localStorage = window.localStorage;
function deviceId() {
// XXX: is Math.random()'s deterministicity a problem here?
var id = Math.floor(Math.random()*16777215).toString(16);
id = "W" + "000000".substring(id.length) + id;
if (localStorage) {
id = localStorage.getItem("mx_device_id") || id;
localStorage.setItem("mx_device_id", id);
}
return id;
}
interface MatrixClientCreds {
homeserverUrl: string,
identityServerUrl: string,
userId: string,
deviceId: string,
accessToken: string,
guest: boolean,
}
@ -87,6 +77,7 @@ class MatrixClientPeg {
homeserverUrl: this.matrixClient.baseUrl,
identityServerUrl: this.matrixClient.idBaseUrl,
userId: this.matrixClient.credentials.userId,
deviceId: this.matrixClient.getDeviceId(),
accessToken: this.matrixClient.getAccessToken(),
guest: this.matrixClient.isGuest(),
};
@ -98,12 +89,12 @@ class MatrixClientPeg {
idBaseUrl: creds.identityServerUrl,
accessToken: creds.accessToken,
userId: creds.userId,
deviceId: creds.deviceId,
timelineSupport: true,
};
if (localStorage) {
opts.sessionStore = new Matrix.WebStorageSessionStore(localStorage);
opts.deviceId = deviceId();
}
this.matrixClient = Matrix.createClient(opts);

View File

@ -330,6 +330,7 @@ class Login extends Signup {
return client.registerGuest().then((creds) => {
return {
userId: creds.user_id,
deviceId: creds.device_id,
accessToken: creds.access_token,
homeserverUrl: this._hsUrl,
identityServerUrl: this._isUrl,
@ -364,6 +365,7 @@ class Login extends Signup {
homeserverUrl: self._hsUrl,
identityServerUrl: self._isUrl,
userId: data.user_id,
deviceId: data.device_id,
accessToken: data.access_token
});
}, function(error) {
@ -387,6 +389,7 @@ class Login extends Signup {
homeserverUrl: self._fallbackHsUrl,
identityServerUrl: self._isUrl,
userId: data.user_id,
deviceId: data.device_id,
accessToken: data.access_token
});
}, function(fallback_error) {

View File

@ -154,6 +154,7 @@ module.exports = React.createClass({
}
self.props.onLoggedIn({
userId: response.user_id,
deviceId: response.device_id,
homeserverUrl: self.registerLogic.getHomeserverUrl(),
identityServerUrl: self.registerLogic.getIdentityServerUrl(),
accessToken: response.access_token
@ -279,7 +280,7 @@ module.exports = React.createClass({
var returnToAppJsx;
if (this.props.onCancelClick) {
returnToAppJsx =
returnToAppJsx =
<a className="mx_Login_create" onClick={this.props.onCancelClick} href="#">
Return to app
</a>