usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [2/3] git commit: added destroyToken and logoutAndDestroyToken functions
Date Mon, 24 Feb 2014 20:22:24 GMT
added destroyToken and logoutAndDestroyToken functions


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/09880621
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/09880621
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/09880621

Branch: refs/pull/59/merge
Commit: 09880621aadc86340c784b48d54f3e62a1fb289b
Parents: 9aff385
Author: amuramoto <amuramoto@apigee.com>
Authored: Mon Feb 24 11:43:02 2014 -0800
Committer: amuramoto <amuramoto@apigee.com>
Committed: Mon Feb 24 11:43:02 2014 -0800

----------------------------------------------------------------------
 sdks/html5-javascript/lib/modules/Client.js | 64 ++++++++++++++++++++++++
 1 file changed, 64 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/09880621/sdks/html5-javascript/lib/modules/Client.js
----------------------------------------------------------------------
diff --git a/sdks/html5-javascript/lib/modules/Client.js b/sdks/html5-javascript/lib/modules/Client.js
index 38db3b1..8a0e3d2 100644
--- a/sdks/html5-javascript/lib/modules/Client.js
+++ b/sdks/html5-javascript/lib/modules/Client.js
@@ -682,6 +682,70 @@
     this.setToken();
   };
 
+    /*
+    *  A public method to destroy access tokens on the server
+    *
+    *  @method logout
+    *  @public    
+    *	 @param {string} username	the user associated with the token to revoke
+    *	 @param {string} token set to 'null' to revoke the token of the currently logged in
user 
+    *  	 or set to token value to revoke a specific token
+    *	 @param {string} revokeAll set to 'true' to revoke all tokens for the user        
   
+    *  @return none
+    */
+		Usergrid.Client.prototype.destroyToken = function (username, token, revokeAll) {
+      var options = {
+	        client:self,
+	        method:'PUT',	        
+				}
+				
+      if (revokeAll == true) {
+				options.endpoint = 'users/'+username+'/revoketokens';
+			} else if (token == null) {
+				options.endpoint = 'users/'+username+'/revoketoken?token='+this.getToken();
+			} else {
+				options.endpoint = 'users/'+username+'/revoketoken?token='+token;
+			}
+      this.request(options, function(err,data) {
+		    if (err) {
+	          if (self.logging) {
+	            console.log('error destroying access token');
+	          }
+	          doCallback(callback, [err, data, null], self);
+	        } else {
+	          if (revokeAll == true) {
+	            console.log('all user tokens invalidated');
+	          } else {
+							console.log('token invalidated');
+	          }
+	          doCallback(callback, [err, data, null], self);
+	        }
+      });
+	  };
+  
+    /*
+    *  A public method to log out an app user - clears all user fields from client
+    *  and destroys the access token on the server.
+    *
+    *  @method logout
+    *  @public
+    *	 @param {string} username the user associated with the token to revoke
+    *	 @param {string} token set to 'null' to revoke the token of the currently logged in
user 
+    *  	 or set to token value to revoke a specific token
+    *	 @param {string} revokeAll set to 'true' to revoke all tokens for the user        
+    *  @return none
+    */
+    Usergrid.Client.prototype.logoutAndDestroyToken = function(username, token, revokeAll)
{
+			if (username == null) {
+				console.log('username required to revoke tokens');
+			} else {
+				this.destroyToken(username,token,revokeAll);
+				if (revokeAll == true || token == this.getToken() || token == null) {
+		    	this.setToken(null);
+		    }
+		  }
+    };
+
   /*
    *  A private method to build the curl call to display on the command line
    *


Mime
View raw message