From 01306a4a2b0289c8b4aec3422aa25c1cbd285586 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 18 Dec 2014 01:17:57 -0800 Subject: [PATCH] GUAC-932: Clean up auth service. Change token service path to /api/tokens. --- .../net/basic/rest/auth/TokenRESTService.java | 2 +- .../app/auth/service/authenticationService.js | 32 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/auth/TokenRESTService.java b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/auth/TokenRESTService.java index 95a8e28b7..6db943908 100644 --- a/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/auth/TokenRESTService.java +++ b/guacamole/src/main/java/org/glyptodon/guacamole/net/basic/rest/auth/TokenRESTService.java @@ -48,7 +48,7 @@ import org.slf4j.LoggerFactory; * * @author James Muehlner */ -@Path("/token") +@Path("/tokens") @Produces(MediaType.APPLICATION_JSON) public class TokenRESTService { diff --git a/guacamole/src/main/webapp/app/auth/service/authenticationService.js b/guacamole/src/main/webapp/app/auth/service/authenticationService.js index aafe92d2d..2070b25aa 100644 --- a/guacamole/src/main/webapp/app/auth/service/authenticationService.js +++ b/guacamole/src/main/webapp/app/auth/service/authenticationService.js @@ -28,20 +28,33 @@ angular.module('auth').factory('authenticationService', ['$http', '$cookieStore' var service = {}; + /** + * The unique identifier of the local cookie which stores the user's + * current authentication token and user ID. + * + * @type String + */ var AUTH_COOKIE_ID = "GUAC_AUTH"; /** * Makes a request to authenticate a user using the token REST API endpoint, - * returning a promise that can be used for processing the results of the call. + * returning a promise that succeeds only if the login operation was + * successful. The resulting authentication data can be retrieved later + * via getCurrentToken() or getCurrentUserID(). * - * @param {String} username The username to log in with. - * @param {String} password The password to log in with. - * @returns {Promise} A promise for the HTTP call. + * @param {String} username + * The username to log in with. + * + * @param {String} password + * The password to log in with. + * + * @returns {Promise} + * A promise which succeeds only if the login operation was successful. */ service.login = function login(username, password) { return $http({ method: 'POST', - url: 'api/token', + url: 'api/tokens', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, @@ -59,14 +72,17 @@ angular.module('auth').factory('authenticationService', ['$http', '$cookieStore' /** * Makes a request to logout a user using the login REST API endpoint, - * returning a promise that can be used for processing the results of the call. + * returning a promise succeeds only if the logout operation was + * successful. * - * @returns {Promise} A promise for the HTTP call. + * @returns {Promise} + * A promise which succeeds only if the logout operation was + * successful. */ service.logout = function logout() { return $http({ method: 'DELETE', - url: 'api/token/' + encodeURIComponent(service.getCurrentToken()) + url: 'api/tokens/' + encodeURIComponent(service.getCurrentToken()) }); };