Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

auth0

Package Overview
Dependencies
Maintainers
5
Versions
156
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

auth0 - npm Package Compare versions

Comparing version 0.7.1 to 0.8.0

examples/custom-signup/custom-signup.js

51

lib/api.js

@@ -314,2 +314,30 @@ var request = require('request');

api.getUserMetadata = function(accessToken, userId, cb) {
var options = {
url: this.apiUrl + '/users/' + userId + '/metadata',
headers: {
'Authorization': 'Bearer ' + accessToken,
}
};
request.get(options, function(err, res, data) {
if (err) {
return cb(err);
}
if (res.statusCode.toString().substr(0, 1) !== '2') {
return cb(new ApiError(data, res.statusCode));
}
try {
data = JSON.parse(data);
} catch (e) {
return cb(e);
}
return cb(null, data);
});
};
// TODO Validate metadata argument
api.updateUserMetadata = function(accessToken, userId, metadata, cb) {

@@ -337,2 +365,25 @@ var options = {

// TODO Validate metadata argument
api.patchUserMetadata = function(accessToken, userId, metadata, cb) {
var options = {
url: this.apiUrl + '/users/' + userId + '/metadata',
headers: {
'Authorization': 'Bearer ' + accessToken,
},
json: metadata,
};
request.patch(options, function(err, res, data) {
if (err) {
return cb(err);
}
if (res.statusCode.toString().substr(0, 1) !== '2') {
return cb(new ApiError(data, res.statusCode));
}
return cb();
});
};
api.deleteUser = function(accessToken, userId, cb) {

@@ -339,0 +390,0 @@ var options = {

2

package.json
{
"name": "auth0",
"version": "0.7.1",
"version": "0.8.0",
"description": "Client library for the Auth0 platform",

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

@@ -193,5 +193,15 @@ Node.js client library for the [Auth0](https://auth0.com) platform.

### api.getUserMetadata(userId, callback)
This method retrieves the metadata for a user. `metadata` is an object that includes custom fields for the user referenced by `userId`.
~~~js
api.getUserMetadata("a-user-id", function(err, metadata) {
// returns error if there was a problem, otherwise the user's metadata
});
~~~
### api.updateUserMetadata(userId, metadata, callback)
This method updates the metadata for a user. `metadata` is an object, and the fields in that object will be set on the user referenced by `userId`.
This method updates the metadata for a user. `metadata` is an object, and the fields in that object will be set on the user referenced by `userId`. **Note:** the entire `metadata` object is replaced with this method. To update select fields, use the `patchUserMetadata` method.

@@ -204,2 +214,12 @@ ~~~js

### api.patchUserMetadata(userId, metadata, callback)
This method patches the metadata for a user. `metadata` is an object, and only the fields included in the patch will be updated for the user referenced by `userId`.
~~~js
api.patchUserMetadata("a-user-id", {my_special_data: {a: "e"}}, function(err) {
// if there was a problem, err will be non-null
});
~~~
### api.deleteUser(userId, callback)

@@ -206,0 +226,0 @@

@@ -51,3 +51,3 @@ var expect = require('chai').expect;

it('should fail when request fail', function (done) {
it('should fail when request fails', function (done) {
var error = 'Error: Token could not be retrieved';

@@ -98,3 +98,3 @@

});
it('should fail when request fail', function (done) {
it('should fail when request fails', function (done) {
var reqUserData = {email: 'john@doe.com'}, resError = 'Error creating user';

@@ -124,3 +124,3 @@

describe('impersonateUser', function () {
describe('impersonateUser', function () {
it('should work on request success', function (done) {

@@ -189,3 +189,3 @@ var reqData = {

});
it('should fail when request fail', function (done) {
it('should fail when request fails', function (done) {
var reqUserData = {userId: 'auth0|omguser', email: 'doge@auth0.com', verify: true};

@@ -246,3 +246,3 @@ var resError = 'Error creating user';

});
it('should fail when request fail', function (done) {
it('should fail when request fails', function (done) {
var reqUserData = {userId: 'auth0|omguser', password: 'sosecretsuchcrypto', verify: true};

@@ -276,2 +276,98 @@ var resError = 'Error creating user';

});
describe('getUserMetadata', function () {
it('should work on request success', function (done) {
var reqUserData = {userId: 'auth0|omguser'};
var resUserData = {some: 'metadata'};
var scope = nock('https://' + domain)
.post('/oauth/token', qs)
.reply(200, {
'access_token': accessToken,
'token_type': 'bearer'
})
.get('/api/users/' + reqUserData.userId + '/metadata')
.matchHeader('Authorization', 'Bearer ' + accessToken)
.reply(200, resUserData);
api.getUserMetadata(reqUserData.userId, function (err, userData) {
expect(err).to.not.exist;
expect(userData).to.be.deep.equal(resUserData);
expect(scope.isDone()).to.be.equal(true);
nock.cleanAll();
done();
});
});
it('should fail when request fails', function (done) {
var reqUserData = {userId: 'auth0|omguser'};
var resError = 'Error creating user';
var scope = nock('https://' + domain)
.post('/oauth/token', qs)
.reply(200, {
'access_token': accessToken,
'token_type': 'bearer'
})
.get('/api/users/' + reqUserData.userId + '/metadata')
.matchHeader('Authorization', 'Bearer ' + accessToken)
.reply(401, resError);
api.getUserMetadata(reqUserData.userId, function (err, userData) {
expect(err).not.to.be.equal(null);
expect(err.name).to.be.equal('ApiError');
expect(err.statusCode).to.be.equal(401);
expect(userData).to.not.exist;
expect(scope.isDone()).to.be.equal(true);
nock.cleanAll();
done();
});
});
});
describe('patchUserMetadata', function () {
it('should work on request success', function (done) {
var reqUserData = {userId: 'auth0|omguser'};
var reqUserMetadata = {some: 'metadata'};
var resUserData = {some: 'metadata'};
var scope = nock('https://' + domain)
.post('/oauth/token', qs)
.reply(200, {
'access_token': accessToken,
'token_type': 'bearer'
})
.patch('/api/users/' + reqUserData.userId + '/metadata', reqUserMetadata)
.matchHeader('Authorization', 'Bearer ' + accessToken)
.reply(200, resUserData);
api.patchUserMetadata(reqUserData.userId, reqUserMetadata, function (err) {
expect(err).to.not.exist;
expect(scope.isDone()).to.be.equal(true);
nock.cleanAll();
done();
});
});
it('should fail when request fails', function (done) {
var reqUserData = {userId: 'auth0|omguser'};
var reqUserMetadata = {some: 'metadata'};
var resError = 'Error creating user';
var scope = nock('https://' + domain)
.post('/oauth/token', qs)
.reply(200, {
'access_token': accessToken,
'token_type': 'bearer'
})
.patch('/api/users/' + reqUserData.userId + '/metadata', reqUserMetadata)
.matchHeader('Authorization', 'Bearer ' + accessToken)
.reply(401, resError);
api.patchUserMetadata(reqUserData.userId, reqUserMetadata, function (err) {
expect(err).not.to.be.equal(null);
expect(err.name).to.be.equal('ApiError');
expect(err.statusCode).to.be.equal(401);
expect(scope.isDone()).to.be.equal(true);
nock.cleanAll();
done();
});
});
});
});

@@ -304,3 +400,3 @@

});
it('should fail when request fail', function (done) {
it('should fail when request fails', function (done) {
var domain = 'my-domain.auth0.com';

@@ -307,0 +403,0 @@ var userAccessToken = 'an-user-access-token';

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