From bbcbf951cc041d90d6c075a8228b94f7abbd8092 Mon Sep 17 00:00:00 2001 From: Shankari Date: Thu, 26 May 2022 23:43:30 -0700 Subject: [PATCH 1/5] Implement the initial random token creation This pulls out the random token generation parts of https://github.com/e-mission/e-mission-phone/commit/7391214a256be497d8451345a5f5fde725b9c3c7 Through copy-pasting --- www/js/intro.js | 14 ++++++++++++++ www/templates/intro/login.html | 16 ++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/www/js/intro.js b/www/js/intro.js index 28eaec601..18aa4d286 100644 --- a/www/js/intro.js +++ b/www/js/intro.js @@ -70,11 +70,25 @@ angular.module('emission.intro', ['emission.splash.startprefs', $scope.overallStatus = false; + // Adapted from https://stackoverflow.com/a/63363662/4040267 + // made available under a CC BY-SA 4.0 license + + $scope.generateRandomToken = function(length) { + var randomInts = window.crypto.getRandomValues(new Uint8Array(length * 2)); + var randomChars = Array.from(randomInts).map((b) => String.fromCharCode(b)); + var randomString = randomChars.join(""); + var validRandomString = window.btoa(randomString).replace(/[+/]/g, ""); + return validRandomString.substring(0, length); + } + $scope.disagree = function() { $state.go('root.main.heatmap'); }; $scope.agree = function() { + $scope.randomToken = $scope.generateRandomToken(8); + window.Logger.log("Signing in with random token "+$scope.randomToken); + StartPrefs.markConsented().then(function(response) { $ionicHistory.clearHistory(); if ($state.is('root.intro')) { diff --git a/www/templates/intro/login.html b/www/templates/intro/login.html index 409173bc0..3dd4c845c 100644 --- a/www/templates/intro/login.html +++ b/www/templates/intro/login.html @@ -1,14 +1,18 @@
-

Login via google

+

Login via token

+
Suggestion: {{randomToken}}
-Currently, we only support logging in via google, since they support techniques -such as two factor authentication for greater security. Participants at UC -Berkeley can choose to login using either their CalNet ID or a personal gmail -account. + +We will now ask you to select a unique passphrase that will be used to identify +you in the system. If you prefer an autogenerated value, you can use {{randomToken}}. +

 

+You will need the passphrase if you want to access your data from another +device such as your laptop or a new phone. +
- +
From 53f85b33d1f6ddf3a877fa965bc56bfd7bf89f7e Mon Sep 17 00:00:00 2001 From: Shankari Date: Wed, 30 Sep 2020 23:30:18 -0700 Subject: [PATCH 2/5] Switch the login to an autogenerated token that is set directly Finally we get to use the new `setPromptedAuthToken` method. This raises a bunch of new questions: - if the user switches phones or uninstalls + reinstalls, how do they enter their old token? - how do they write their old token down - should we give them a choice between autogenerated and human generated Fortunately, since this is going to collect data for 2-3 days, none of these need to be answered right now. --- www/js/intro.js | 2 +- www/templates/intro/login.html | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/www/js/intro.js b/www/js/intro.js index 18aa4d286..4d42ae785 100644 --- a/www/js/intro.js +++ b/www/js/intro.js @@ -120,7 +120,7 @@ angular.module('emission.intro', ['emission.splash.startprefs', } $scope.login = function() { - window.cordova.plugins.BEMJWTAuth.signIn().then(function(userEmail) { + window.cordova.plugins.BEMJWTAuth.setPromptedAuthToken($scope.randomToken).then(function(userEmail) { // ionicToast.show(message, position, stick, time); // $scope.next(); ionicToast.show(userEmail, 'middle', false, 2500); diff --git a/www/templates/intro/login.html b/www/templates/intro/login.html index 3dd4c845c..073c42406 100644 --- a/www/templates/intro/login.html +++ b/www/templates/intro/login.html @@ -1,18 +1,16 @@
-

Login via token

-
Suggestion: {{randomToken}}
+

Login via anonymous token

+
Token {{randomToken}}
- -We will now ask you to select a unique passphrase that will be used to identify -you in the system. If you prefer an autogenerated value, you can use {{randomToken}}. +This unique randomly generated token is your identifier in the system.

 

-You will need the passphrase if you want to access your data from another -device such as your laptop or a new phone. - +Nobody other than you knows that you are associated with this token. If you +want to communicate with the research team about the data collected about you, +please be prepared to provide this token.
- +
From 751f9b4a71d8982a10f15dee9c40d40f56160e5c Mon Sep 17 00:00:00 2001 From: Shankari Date: Mon, 7 Dec 2020 17:59:28 -0800 Subject: [PATCH 3/5] Allow users to enter a prior token in the login screen Can change this based on feedback from initial testers --- www/js/intro.js | 45 ++++++++++++++++++++++++++++++++-- www/templates/intro/login.html | 6 ++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/www/js/intro.js b/www/js/intro.js index 4d42ae785..aef2c1325 100644 --- a/www/js/intro.js +++ b/www/js/intro.js @@ -119,8 +119,49 @@ angular.module('emission.intro', ['emission.splash.startprefs', }); } - $scope.login = function() { - window.cordova.plugins.BEMJWTAuth.setPromptedAuthToken($scope.randomToken).then(function(userEmail) { + $scope.loginNew = function() { + $scope.login($scope.randomToken); + }; + + $scope.loginExisting = function() { + $scope.data = {}; + const tokenPopup = $ionicPopup.show({ + template: '', + title: 'Enter the existing token that you have', + scope: $scope, + buttons: [ + { + text: 'OK', + type: 'button-positive', + onTap: function(e) { + if (!$scope.data.existing_token) { + //don't allow the user to close unless he enters a username + + e.preventDefault(); + } else { + return $scope.data.existing_token; + } + } + },{ + text: 'Cancel', + type: 'button-stable', + onTap: function(e) { + return null; + } + } + ] + }); + tokenPopup.then(function(token) { + if (token != null) { + $scope.login($scope.randomToken); + } + }).catch(function(err) { + $scope.alertError(err); + }); + }; + + $scope.login = function(token) { + window.cordova.plugins.BEMJWTAuth.setPromptedAuthToken(token).then(function(userEmail) { // ionicToast.show(message, position, stick, time); // $scope.next(); ionicToast.show(userEmail, 'middle', false, 2500); diff --git a/www/templates/intro/login.html b/www/templates/intro/login.html index 073c42406..91f366f46 100644 --- a/www/templates/intro/login.html +++ b/www/templates/intro/login.html @@ -10,7 +10,11 @@ want to communicate with the research team about the data collected about you, please be prepared to provide this token.
- + + +If you already have a token from a previous install, you can use it instead to retain the same account. Note that there are no incorrect tokens. If you enter a token that does not match an existing one, we will create a new account. +
+ From ce104545a36dfc5ec309071288898181895e4175 Mon Sep 17 00:00:00 2001 From: Shankari Date: Thu, 26 May 2022 23:52:36 -0700 Subject: [PATCH 4/5] Fix existing login For existing login, use specified token, not the random token This is a partial application of https://github.com/e-mission/e-mission-phone/commit/0ed8466b1c3e1e328374aa86b5ba6448c2a9103e --- www/js/intro.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/js/intro.js b/www/js/intro.js index aef2c1325..e139887b1 100644 --- a/www/js/intro.js +++ b/www/js/intro.js @@ -153,7 +153,7 @@ angular.module('emission.intro', ['emission.splash.startprefs', }); tokenPopup.then(function(token) { if (token != null) { - $scope.login($scope.randomToken); + $scope.login(token); } }).catch(function(err) { $scope.alertError(err); From 07fab2b4db1ec0910f0b9256b0af7bd52ea89e52 Mon Sep 17 00:00:00 2001 From: Shankari Date: Thu, 26 May 2022 23:58:03 -0700 Subject: [PATCH 5/5] Bump up token size to 16 characters --- www/js/intro.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/js/intro.js b/www/js/intro.js index e139887b1..df7b3d00c 100644 --- a/www/js/intro.js +++ b/www/js/intro.js @@ -86,7 +86,7 @@ angular.module('emission.intro', ['emission.splash.startprefs', }; $scope.agree = function() { - $scope.randomToken = $scope.generateRandomToken(8); + $scope.randomToken = $scope.generateRandomToken(16); window.Logger.log("Signing in with random token "+$scope.randomToken); StartPrefs.markConsented().then(function(response) {