GUACAMOLE-549: Store auth token within localStorage rather than cookie.
Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/884a9c0e Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/884a9c0e Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/884a9c0e Branch: refs/heads/master Commit: 884a9c0ee987f9cb49a69ceb17eb0e2267eed058 Parents: 1686e6f Author: Michael Jumper <[email protected]> Authored: Wed Apr 18 20:44:08 2018 -0700 Committer: Michael Jumper <[email protected]> Committed: Thu Apr 19 12:49:19 2018 -0700 ---------------------------------------------------------------------- guacamole/pom.xml | 6 ------ .../src/main/webapp/app/auth/authModule.js | 4 +++- .../app/auth/service/authenticationService.js | 22 ++++++++++---------- guacamole/src/main/webapp/index.html | 1 - 4 files changed, 14 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/884a9c0e/guacamole/pom.xml ---------------------------------------------------------------------- diff --git a/guacamole/pom.xml b/guacamole/pom.xml index 9fa9fce..12d6c5c 100644 --- a/guacamole/pom.xml +++ b/guacamole/pom.xml @@ -329,12 +329,6 @@ </dependency> <dependency> <groupId>org.webjars.bower</groupId> - <artifactId>angular-cookies</artifactId> - <version>1.3.16</version> - <scope>runtime</scope> - </dependency> - <dependency> - <groupId>org.webjars.bower</groupId> <artifactId>angular-route</artifactId> <version>1.3.16</version> <scope>runtime</scope> http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/884a9c0e/guacamole/src/main/webapp/app/auth/authModule.js ---------------------------------------------------------------------- diff --git a/guacamole/src/main/webapp/app/auth/authModule.js b/guacamole/src/main/webapp/app/auth/authModule.js index ff8851e..7faaf87 100644 --- a/guacamole/src/main/webapp/app/auth/authModule.js +++ b/guacamole/src/main/webapp/app/auth/authModule.js @@ -20,4 +20,6 @@ /** * The module for authentication and management of tokens. */ -angular.module('auth', ['ngCookies']); +angular.module('auth', [ + 'storage' +]); http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/884a9c0e/guacamole/src/main/webapp/app/auth/service/authenticationService.js ---------------------------------------------------------------------- diff --git a/guacamole/src/main/webapp/app/auth/service/authenticationService.js b/guacamole/src/main/webapp/app/auth/service/authenticationService.js index 74f0570..2b64a5b 100644 --- a/guacamole/src/main/webapp/app/auth/service/authenticationService.js +++ b/guacamole/src/main/webapp/app/auth/service/authenticationService.js @@ -46,10 +46,10 @@ angular.module('auth').factory('authenticationService', ['$injector', var Error = $injector.get('Error'); // Required services - var $cookieStore = $injector.get('$cookieStore'); - var $http = $injector.get('$http'); - var $q = $injector.get('$q'); - var $rootScope = $injector.get('$rootScope'); + var $http = $injector.get('$http'); + var $q = $injector.get('$q'); + var $rootScope = $injector.get('$rootScope'); + var localStorageService = $injector.get('localStorageService'); var service = {}; @@ -62,12 +62,12 @@ angular.module('auth').factory('authenticationService', ['$injector', var cachedResult = null; /** - * The unique identifier of the local cookie which stores the result of the - * last authentication attempt. + * The unique identifier of the local storage key which stores the result + * of the last authentication attempt. * * @type String */ - var AUTH_COOKIE_ID = "GUAC_AUTH"; + var AUTH_STORAGE_KEY = 'GUAC_AUTH'; /** * Retrieves the last successful authentication result. If the user has not @@ -85,7 +85,7 @@ angular.module('auth').factory('authenticationService', ['$injector', return cachedResult; // Return explicit null if no auth data is currently stored - var data = $cookieStore.get(AUTH_COOKIE_ID); + var data = localStorageService.getItem(AUTH_STORAGE_KEY); if (!data) return null; @@ -107,7 +107,7 @@ angular.module('auth').factory('authenticationService', ['$injector', // Clear the currently-stored result if the last attempt failed if (!data) { cachedResult = null; - $cookieStore.remove(AUTH_COOKIE_ID); + localStorageService.removeItem(AUTH_STORAGE_KEY); } // Otherwise store the authentication attempt directly @@ -116,9 +116,9 @@ angular.module('auth').factory('authenticationService', ['$injector', // Always store in cache cachedResult = data; - // Store cookie ONLY if not anonymous + // Persist result past tab/window closure ONLY if not anonymous if (data.username !== AuthenticationResult.ANONYMOUS_USERNAME) - $cookieStore.put(AUTH_COOKIE_ID, data); + localStorageService.setItem(AUTH_STORAGE_KEY, data); } http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/884a9c0e/guacamole/src/main/webapp/index.html ---------------------------------------------------------------------- diff --git a/guacamole/src/main/webapp/index.html b/guacamole/src/main/webapp/index.html index 376245f..14321de 100644 --- a/guacamole/src/main/webapp/index.html +++ b/guacamole/src/main/webapp/index.html @@ -62,7 +62,6 @@ <!-- AngularJS --> <script type="text/javascript" src="webjars/angular/1.3.16/angular.min.js"></script> - <script type="text/javascript" src="webjars/angular-cookies/1.3.16/angular-cookies.min.js"></script> <script type="text/javascript" src="webjars/angular-route/1.3.16/angular-route.min.js"></script> <script type="text/javascript" src="webjars/angular-touch/1.3.16/angular-touch.min.js"></script>
