Socket
Socket
Sign inDemoInstall

usergrid

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

usergrid - npm Package Compare versions

Comparing version 0.10.1 to 0.10.2

8

changelog.md
##Change log
###0.10.2
- Removed local caching of user object in client
###0.10.1
- Minor refactor of the SDK to bring congruity with the App services Javascript SDK
###0.10.0

@@ -4,0 +12,0 @@ - Complete refactor of the entire module

83

lib/usergrid.js

@@ -25,3 +25,3 @@ /**

var Usergrid = {};
Usergrid.SDK_VERSION = '0.10.01';
Usergrid.SDK_VERSION = '0.10.02';

@@ -46,3 +46,2 @@ //authentication type constants

this.token = options.token || null;
this.user = null;

@@ -231,5 +230,3 @@ //other options

} else {
user = new Usergrid.Entity('users');
user.set(data.user);
self.user = user;
user = new Usergrid.Entity('users', data.user);
self.token = data.access_token;

@@ -267,5 +264,3 @@ }

} else {
user = new Usergrid.Entity('users');
user.set(data.user);
self.user = user;
user = new Usergrid.Entity('users', data.user);
self.token = data.access_token;

@@ -279,5 +274,40 @@ }

/*
* A public method to get the currently logged in user entity
*
* @method getLoggedInUser
* @public
* @param {function} callback
* @return {callback} callback(err, data)
*/
Usergrid.Client.prototype.getLoggedInUser = function (callback) {
if (!this.token) {
callback(true, null, null);
} else {
var self = this;
var options = {
method:'GET',
endpoint:'users/me',
};
this.request(options, function(err, data) {
if (err) {
if (self.logging) {
console.log('error trying to log user in');
}
if (typeof(callback) === 'function') {
callback(err, data, null);
}
} else {
var user = new Usergrid.Entity('users', data.user);
if (typeof(callback) === 'function') {
callback(err, data, user);
}
}
});
}
}
/**
* A public method to test if a user is logged in - does not guarantee that the token is still valid,
* but rather that one exists, and that there is a valid UUID
* but rather that one exists
*

@@ -289,13 +319,19 @@ * @method isLoggedIn

Usergrid.Client.prototype.isLoggedIn = function () {
var user = this.user;
var haveUser = (user && this.token);
if (!haveUser) {
return false;
if (this.token) {
return true;
}
if (!isUUID(user.get('uuid'))) {
return false;
}
return true;
return false;
}
/**
* A public method to log out an app user - clears all user fields from client
*
* @method logout
* @public
* @return none
*/
Usergrid.Client.prototype.logout = function () {
this.token = null;
}
/*

@@ -337,16 +373,3 @@ * A private method to build the curl call to display on the command line

/**
* A public method to log out an app user - clears all user fields from client
*
* @method logout
* @public
* @return none
*/
Usergrid.Client.prototype.logout = function () {
this.user = null;
this.token = null;
}
/**

@@ -353,0 +376,0 @@ * A class to Model a Usergrid Entity.

{
"name": "usergrid",
"version": "0.10.1",
"version": "0.10.2",
"description": "A Node.js module for making API calls to App Services (Usergrid) from within Node.js",

@@ -5,0 +5,0 @@ "main": "./lib/usergrid.js",

##Version
Current Version: **0.10.1**
Current Version: **0.10.2**

@@ -448,6 +448,11 @@ See change log:

###To log a user in
Up to this point, we have shown how you can use the client secret / client id combination to authenticate your calls against the API. For a server-side Node.js app, this may be all you need. However, if you do find that your app requires that you authenticate an individual user, this section shows you how.
Up to this point, we have shown how you can use the client secret / client id combination to authenticate your calls against the API. For a server-side Node.js app, this may be all you need. However, if you do find that your app requires that you authenticate an individual user, you have several options.
Logging a user in means sending the user's username and password to the server, and getting back an access (OAuth) token. You can then use this token to make calls to the API on the User's behalf. The following example shows how to log a user in, then how to make a new client object to use for the app user's calls:
The first is to use client-side authentication with Ajax. If you want to opt for this method, take a look at our Javascript SDK. The syntax for usage is the same as this Node.js module, so it will be easy to pick up:
<https://github.com/apigee/usergrid-javascript-sdk>
The other method is to log the user in server-side. When you log a user in, the API will return an OAuth token for you to use for calls to the API on the user's behalf. Once that token is returned, you can either make a new client just for the user, or change the auth method on the existing client. These methods are described below:
username = 'marty';

@@ -460,14 +465,4 @@ password = 'mysecurepassword';

} else {
//once a user has logged in, thier user object is stored
//in the client and you can access it this way:
var user = client.user;
success('user has been logged in');
//so you can then get their username (or other info):
var username = user.get('username');
//you can also detect if the user is logged in:
if (client.isLoggedIn()) {
success('user has been logged in');
}
//the login call will return an OAuth token, which is saved

@@ -477,43 +472,57 @@ //in the client object for later use. Access it this way:

//then make a new client just for the app user
//then make a new client just for the app user, then use this
//client to make calls against the API
var appUserClient = new usergrid.client({
orgName:'yourorgname',
appName:'yourappname',
authType:usergrid.APP_USER,
authType:usergrid.AUTH_APP_USER,
token:token
});
//then use this client to make calls against the API
//alternitavely, you can change the authtype of the client:
client.authType = usergrid.AUTH_APP_USER;
//to log the user out, call the logout() method
appUserClient.logout();
client.logout();
//Then make calls against the API. For example, you can
//get the user entity this way:
client.getLoggedInUser(function(err, data, user) {
if(err) {
error('could not get logged in user');
} else {
success('got logged in user');
//verify the logout worked
if (client.isLoggedIn()) {
error('logout failed');
} else {
success('user has been logged out');
}
//you can then get info from the user entity object:
var username = user.get('username');
notice('logged in user was: ' + username);
}
}
);
//to log the user out, call the logout() method
appUserClient.logout();
client.logout();
//verify the logout worked
if (client.isLoggedIn()) {
error('logout failed');
} else {
success('user has been logged out');
}
Another way to make calls for the app user is to simply change the auth method on the existing client object:
//since we don't need to App User level calls anymore,
//set the authtype back to client:
client.authType = usergrid.AUTH_CLIENT_ID;
client.authType = usergrid.APP_USER;
runner(step, marty);
}
});
After this statement is called, all calls will use the user token instead of the client secret / id combo (application level). To switch back, just enable the client secret/id combo instead:
}
}
);
client.authType = usergrid.AUTH_CLIENT_ID;
**Note:** you can also set the client to use no authentication. You would use this method if you are using the default Sandbox app that was automatically created when your account was set up:
To recap, once a user has been logged in, and an OAuth token has been acquired, use one of the two methods to make calls to the API:
client.authType = usergrid.AUTH_NONE;
1. Use the same client object and change auth types before each call
With this setting enabled, no authentication will be provided to the database. You will likely only use this setting if you are testing with the Sandbox app.
2. Grab the token and make a new client object specifically for user calls.
To recap, once a user has been logged in, and an OAuth token has been acquired, use one of the two methods to make calls to the API: 1.) use the same client object and change auth types before each call, or, 2.) make a new client object for user calls. Either method will work.
Either method will work.

@@ -540,4 +549,2 @@

d
## Contributing

@@ -544,0 +551,0 @@ We welcome your enhancements!

@@ -555,14 +555,4 @@ /**

} else {
//once a user has logged in, thier user object is stored
//in the client and you can access it this way:
var user = client.user;
success('user has been logged in');
//so you can then get their username (or other info):
var username = user.get('username');
//you can also detect if the user is logged in:
if (client.isLoggedIn()) {
success('user has been logged in');
}
//the login call will return an OAuth token, which is saved

@@ -572,24 +562,45 @@ //in the client object for later use. Access it this way:

//then make a new client just for the app user
//then make a new client just for the app user, then use this
//client to make calls against the API
var appUserClient = new usergrid.client({
orgName:'yourorgname',
appName:'yourappname',
authType:usergrid.APP_USER,
authType:usergrid.AUTH_APP_USER,
token:token
});
//then use this client to make calls against the API
//alternitavely, you can change the authtype of the client:
client.authType = usergrid.AUTH_APP_USER;
//to log the user out, call the logout() method
appUserClient.logout();
client.logout();
//Then make calls against the API. For example, you can
//get the user entity this way:
client.getLoggedInUser(function(err, data, user) {
if(err) {
error('could not get logged in user');
} else {
success('got logged in user');
//verify the logout worked
if (client.isLoggedIn()) {
error('logout failed');
} else {
success('user has been logged out');
}
//you can then get info from the user entity object:
var username = user.get('username');
notice('logged in user was: ' + username);
runner(step, marty);
//to log the user out, call the logout() method
appUserClient.logout();
client.logout();
//verify the logout worked
if (client.isLoggedIn()) {
error('logout failed');
} else {
success('user has been logged out');
}
//since we don't need to App User level calls anymore,
//set the authtype back to client:
client.authType = usergrid.AUTH_CLIENT_ID;
runner(step, marty);
}
});
}

@@ -596,0 +607,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc