mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUACAMOLE-549: Store auth token within localStorage rather than cookie.
This commit is contained in:
@@ -327,12 +327,6 @@
|
|||||||
<version>1.3.16</version>
|
<version>1.3.16</version>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.webjars.bower</groupId>
|
|
||||||
<artifactId>angular-cookies</artifactId>
|
|
||||||
<version>1.3.16</version>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.webjars.bower</groupId>
|
<groupId>org.webjars.bower</groupId>
|
||||||
<artifactId>angular-route</artifactId>
|
<artifactId>angular-route</artifactId>
|
||||||
|
@@ -20,4 +20,6 @@
|
|||||||
/**
|
/**
|
||||||
* The module for authentication and management of tokens.
|
* The module for authentication and management of tokens.
|
||||||
*/
|
*/
|
||||||
angular.module('auth', ['ngCookies']);
|
angular.module('auth', [
|
||||||
|
'storage'
|
||||||
|
]);
|
||||||
|
@@ -46,10 +46,10 @@ angular.module('auth').factory('authenticationService', ['$injector',
|
|||||||
var Error = $injector.get('Error');
|
var Error = $injector.get('Error');
|
||||||
|
|
||||||
// Required services
|
// Required services
|
||||||
var $cookieStore = $injector.get('$cookieStore');
|
var $http = $injector.get('$http');
|
||||||
var $http = $injector.get('$http');
|
var $q = $injector.get('$q');
|
||||||
var $q = $injector.get('$q');
|
var $rootScope = $injector.get('$rootScope');
|
||||||
var $rootScope = $injector.get('$rootScope');
|
var localStorageService = $injector.get('localStorageService');
|
||||||
|
|
||||||
var service = {};
|
var service = {};
|
||||||
|
|
||||||
@@ -62,12 +62,12 @@ angular.module('auth').factory('authenticationService', ['$injector',
|
|||||||
var cachedResult = null;
|
var cachedResult = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The unique identifier of the local cookie which stores the result of the
|
* The unique identifier of the local storage key which stores the result
|
||||||
* last authentication attempt.
|
* of the last authentication attempt.
|
||||||
*
|
*
|
||||||
* @type String
|
* @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
|
* Retrieves the last successful authentication result. If the user has not
|
||||||
@@ -85,7 +85,7 @@ angular.module('auth').factory('authenticationService', ['$injector',
|
|||||||
return cachedResult;
|
return cachedResult;
|
||||||
|
|
||||||
// Return explicit null if no auth data is currently stored
|
// 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)
|
if (!data)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ angular.module('auth').factory('authenticationService', ['$injector',
|
|||||||
// Clear the currently-stored result if the last attempt failed
|
// Clear the currently-stored result if the last attempt failed
|
||||||
if (!data) {
|
if (!data) {
|
||||||
cachedResult = null;
|
cachedResult = null;
|
||||||
$cookieStore.remove(AUTH_COOKIE_ID);
|
localStorageService.removeItem(AUTH_STORAGE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise store the authentication attempt directly
|
// Otherwise store the authentication attempt directly
|
||||||
@@ -116,9 +116,9 @@ angular.module('auth').factory('authenticationService', ['$injector',
|
|||||||
// Always store in cache
|
// Always store in cache
|
||||||
cachedResult = data;
|
cachedResult = data;
|
||||||
|
|
||||||
// Store cookie ONLY if not anonymous
|
// Persist result past tab/window closure ONLY if not anonymous
|
||||||
if (data.username !== AuthenticationResult.ANONYMOUS_USERNAME)
|
if (data.username !== AuthenticationResult.ANONYMOUS_USERNAME)
|
||||||
$cookieStore.put(AUTH_COOKIE_ID, data);
|
localStorageService.setItem(AUTH_STORAGE_KEY, data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -62,7 +62,6 @@
|
|||||||
|
|
||||||
<!-- AngularJS -->
|
<!-- AngularJS -->
|
||||||
<script type="text/javascript" src="webjars/angular/1.3.16/angular.min.js"></script>
|
<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-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>
|
<script type="text/javascript" src="webjars/angular-touch/1.3.16/angular-touch.min.js"></script>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user