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

auth0

Package Overview
Dependencies
Maintainers
3
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.2.2 to 0.3.1

.jshintrc

262

lib/api.js

@@ -11,8 +11,10 @@ var request = require('request');

api.getRule = function(accessToken, ruleName, done) {
request.get({
url: this.apiUrl + '/rules/' + ruleName,
qs: { access_token: accessToken },
headers: {"Accept": "application/xml" },
}, function(err,r,body) {
if( err ) return done(err);
request.get({
url: this.apiUrl + '/rules/' + ruleName,
headers: {
'Accept': 'application/xml',
'Authorization': 'Bearer ' + accessToken
},
}, function(err,r,body) {
if( err ) { return done(err); }
if (r.statusCode.toString().substr(0, 1) !== '2'){

@@ -22,12 +24,14 @@ return done(new ApiError(body, r.statusCode));

return done(null, body);
});
});
};
api.getRules = function(accessToken, done) {
request.get({
url: this.apiUrl + '/rules',
qs: { access_token: accessToken },
headers: {"Accept": "application/xml" },
}, function(err,r,body) {
if( err ) return done(err);
request.get({
url: this.apiUrl + '/rules',
headers: {
'Accept': 'application/xml',
'Authorization': 'Bearer ' + accessToken
},
}, function(err,r,body) {
if( err ) { return done(err); }
if (r.statusCode.toString().substr(0, 1) !== '2'){

@@ -37,9 +41,11 @@ return done(new ApiError(body, r.statusCode));

return done(null, body);
});
});
};
api.updateRule = function(accessToken, rule, done) {
request.put({
request.put({
url: this.apiUrl + '/rules/' + rule.name,
qs: { access_token: accessToken },
headers: {
'Authorization': 'Bearer ' + accessToken
},
json: rule

@@ -56,9 +62,11 @@ }, function (err, r, body) {

api.deleteRule = function(accessToken, ruleName, done) {
request.del({
request.del({
url: this.apiUrl + '/rules/' + ruleName,
qs: { access_token: accessToken }
headers: {
'Authorization': 'Bearer ' + accessToken
}
}, function (err, r, body) {
if (err) return done(err);
if (r.statusCode === 404) return done(null, null);
if (r.statusCode.toString().substr(0, 1) !== '2') return done(new ApiError(body, r.statusCode));
if (err) { return done(err); }
if (r.statusCode === 404) { return done(null, null); }
if (r.statusCode.toString().substr(0, 1) !== '2') { return done(new ApiError(body, r.statusCode)); }
done();

@@ -69,11 +77,13 @@ });

api.createRule = function(accessToken, rule, done) {
request.post({
url: this.apiUrl + '/rules',
qs: { access_token: accessToken },
json: rule
},
function (err, resp, body) {
if (err) return done(err);
done(null, body);
}.bind(this));
request.post({
url: this.apiUrl + '/rules',
headers: {
'Authorization': 'Bearer ' + accessToken
},
json: rule
},
function (err, resp, body) {
if (err) { return done(err); }
done(null, body);
}.bind(this));
};

@@ -84,4 +94,6 @@

url: this.apiUrl + '/connections',
qs: { access_token: accessToken },
headers: {"Accept": "application/xml"},
headers: {
'Accept': 'application/xml',
'Authorization': 'Bearer ' + accessToken
},
}, function (err, r, body) {

@@ -111,4 +123,7 @@ if (err) { return done(err); }

url: this.apiUrl + '/connections',
qs: { access_token: accessToken, only_socials: true },
headers: {"Accept": "application/xml"}
headers: {
'Authorization': 'Bearer ' + accessToken,
'Accept': 'application/xml'
},
qs: { only_socials: true },
}, function (err, r, body) {

@@ -137,7 +152,7 @@ if (err) { return done(err); }

url: this.apiUrl + '/connections',
qs: {
access_token: accessToken,
only_enterprise: true
},
headers: {"Accept": "application/xml"}
qs: { only_enterprise: true },
headers: {
'Authorization': 'Bearer ' + accessToken,
'Accept': 'application/xml'
}
}, function (err, r, body) {

@@ -183,4 +198,6 @@ if (err) { return done(err); }

var options = {
url: this.apiUrl + "/users/" + userId,
qs: {access_token: accessToken},
url: this.apiUrl + '/users/' + userId,
headers: {
'Authorization': 'Bearer ' + accessToken,
}
};

@@ -193,3 +210,3 @@

if (res.statusCode.toString().substr(0, 1) !== "2") {
if (res.statusCode.toString().substr(0, 1) !== '2') {
return cb(new ApiError(data, res.statusCode));

@@ -208,6 +225,30 @@ }

api.createUser = function(accessToken, userData, done) {
var options = {
url: this.apiUrl + '/users/',
headers: {
'Authorization': 'Bearer ' + accessToken,
},
json: userData
};
request.post(options, function (err, res, body) {
if (err) { return done(err); }
if (res.statusCode === 404) { return done(); }
if (res.statusCode.toString().substr(0, 1) !== '2') {
return done(new ApiError(body.detail || body, res.statusCode));
}
done(null, body);
});
};
api.updateUserMetadata = function(accessToken, userId, metadata, cb) {
var options = {
url: this.apiUrl + "/users/" + userId,
qs: {access_token: accessToken},
url: this.apiUrl + '/users/' + userId,
headers: {
'Authorization': 'Bearer ' + accessToken,
},
json: {metadata: metadata},

@@ -221,3 +262,3 @@ };

if (res.statusCode.toString().substr(0, 1) !== "2") {
if (res.statusCode.toString().substr(0, 1) !== '2') {
return cb(new ApiError(data, res.statusCode));

@@ -232,5 +273,7 @@ }

var options = {
method: "DELETE",
url: this.apiUrl + "/users/" + userId,
qs: {access_token: accessToken},
method: 'DELETE',
url: this.apiUrl + '/users/' + userId,
headers: {
'Authorization': 'Bearer ' + accessToken,
},
};

@@ -243,3 +286,3 @@

if (res.statusCode.toString().substr(0, 1) !== "2") {
if (res.statusCode.toString().substr(0, 1) !== '2') {
return cb(new ApiError(data, res.statusCode));

@@ -274,6 +317,11 @@ }

// nextPageLink already includes a token. It only works for that URL for a
// brief period of time (see hawk bewit)
if(nextPageLink){
req = { url: url.parse(nextPageLink) };
}else {
req = { qs: xtend({ access_token: accessToken }, options) };
req = {
headers: { 'Authorization': 'Bearer ' + accessToken},
qs: options
};
if (connection) {

@@ -293,3 +341,3 @@ req.url = this.apiUrl + '/connections/' + connection + '/users';

request.get(req, function (err, r, body) {
if (err) return done(err);
if (err) { return done(err); }

@@ -328,10 +376,12 @@ if (r.statusCode.toString().substr(0, 1) !== '2'){

url: this.apiUrl + '/connection-templates/' + strategy,
qs: { access_token: accessToken },
headers: {
'Authorization': 'Bearer ' + accessToken,
},
json: options
}, function (err, r, body) {
if (err) return done(err);
if (err) { return done(err); }
if(r.statusCode === 400) {
return done(new ApiError(body.detail || body, 400));
}
if (r.statusCode.toString().substr(0, 1) !== '2') return done(new ApiError(body, r.statusCode));
if (r.statusCode.toString().substr(0, 1) !== '2') { return done(new ApiError(body, r.statusCode)); }
done();

@@ -344,6 +394,8 @@ });

url: this.apiUrl + '/connection-templates/' + strategy,
qs: { access_token: accessToken }
headers: {
'Authorization': 'Bearer ' + accessToken,
}
}, function (err, r, body) {
if (err) return done(err);
if (r.statusCode.toString().substr(0, 1) !== '2') return done(new ApiError(body, r.statusCode));
if (err) { return done(err); }
if (r.statusCode.toString().substr(0, 1) !== '2') { return done(new ApiError(body, r.statusCode)); }
done(null, JSON.parse(body));

@@ -356,6 +408,8 @@ });

url: this.apiUrl + '/connection-templates/' + strategy,
qs: { access_token: accessToken }
headers: {
'Authorization': 'Bearer ' + accessToken,
}
}, function (err, r, body) {
if (err) return done(err);
if (r.statusCode.toString().substr(0, 1) !== '2') return done(new ApiError(body, r.statusCode));
if (err) { return done(err); }
if (r.statusCode.toString().substr(0, 1) !== '2') { return done(new ApiError(body, r.statusCode)); }
done();

@@ -368,6 +422,8 @@ });

url: this.apiUrl + '/strategies',
qs: { access_token: accessToken }
headers: {
'Authorization': 'Bearer ' + accessToken,
}
}, function (err, r, body) {
if (err) return done(err);
if (r.statusCode.toString().substr(0, 1) !== '2') return done(new ApiError(body, r.statusCode));
if (err) { return done(err); }
if (r.statusCode.toString().substr(0, 1) !== '2') { return done(new ApiError(body, r.statusCode)); }
done(null, JSON.parse(body));

@@ -380,7 +436,9 @@ });

url: this.apiUrl + '/connections/' + name,
qs: { access_token: accessToken }
headers: {
'Authorization': 'Bearer ' + accessToken,
}
}, function (err, r, body) {
if (err) return done(err);
if (r.statusCode === 404) return done(null, null);
if (r.statusCode.toString().substr(0, 1) !== '2') return done(new ApiError(body, r.statusCode));
if (err) { return done(err); }
if (r.statusCode === 404) { return done(null, null); }
if (r.statusCode.toString().substr(0, 1) !== '2') { return done(new ApiError(body, r.statusCode)); }
var connection;

@@ -403,3 +461,5 @@

url: this.apiUrl + '/connections',
qs: { access_token: accessToken },
headers: {
'Authorization': 'Bearer ' + accessToken,
},
json: connection

@@ -419,7 +479,9 @@ }, function (err, r, body) {

url: this.apiUrl + '/connections/' + name,
qs: { access_token: accessToken }
headers: {
'Authorization': 'Bearer ' + accessToken,
}
}, function (err, r, body) {
if (err) return done(err);
if (r.statusCode === 404) return done(null, null);
if (r.statusCode.toString().substr(0, 1) !== '2') return done(new ApiError(body, r.statusCode));
if (err) { return done(err); }
if (r.statusCode === 404) { return done(null, null); }
if (r.statusCode.toString().substr(0, 1) !== '2') { return done(new ApiError(body, r.statusCode)); }
var data;

@@ -440,3 +502,5 @@

url: this.apiUrl + '/connections/' + connection.name,
qs: { access_token: accessToken },
headers: {
'Authorization': 'Bearer ' + accessToken,
},
json: connection

@@ -455,7 +519,9 @@ }, function (err, r, body) {

url: this.apiUrl + '/tenants/' + name,
qs: { access_token: accessToken }
headers: {
'Authorization': 'Bearer ' + accessToken,
}
}, function (err, r, body) {
if (err) return done(err);
if (r.statusCode === 404) return done(null, null);
if (r.statusCode.toString().substr(0, 1) !== '2') return done(new ApiError(body, r.statusCode));
if (err) { return done(err); }
if (r.statusCode === 404) { return done(null, null); }
if (r.statusCode.toString().substr(0, 1) !== '2') { return done(new ApiError(body, r.statusCode)); }
done();

@@ -468,8 +534,10 @@ }.bind(this));

url: this.apiUrl + '/clients',
qs: { access_token: accessToken },
headers: {
'Authorization': 'Bearer ' + accessToken,
},
json: options
}, function (err, r, body) {
if (err) return done(err);
if (r.statusCode === 404) return done();
if (r.statusCode.toString().substr(0, 1) !== '2') return done(new ApiError(body.detail || body, r.statusCode));
if (err) { return done(err); }
if (r.statusCode === 404) { return done(); }
if (r.statusCode.toString().substr(0, 1) !== '2') { return done(new ApiError(body.detail || body, r.statusCode)); }

@@ -483,7 +551,9 @@ done(null, body);

url: this.apiUrl + '/clients/' + client.clientID,
qs: { access_token: accessToken },
headers: {
'Authorization': 'Bearer ' + accessToken,
},
json: client
}, function (err, r, body) {
if (err) { return done(err); }
if (r.statusCode.toString().substr(0, 1) !== '2') return done(new ApiError(body.detail || body, r.statusCode));
if (r.statusCode.toString().substr(0, 1) !== '2') { return done(new ApiError(body.detail || body, r.statusCode)); }

@@ -497,7 +567,9 @@ done(null, body);

url: this.apiUrl + '/clients/' + clientID,
qs: { access_token: accessToken }
headers: {
'Authorization': 'Bearer ' + accessToken,
}
}, function (err, r, body) {
if (err) return done(err);
if (r.statusCode === 404) return done();
if (r.statusCode.toString().substr(0, 1) !== '2') return done(new ApiError(body. r.statusCode));
if (err) { return done(err); }
if (r.statusCode === 404) { return done(); }
if (r.statusCode.toString().substr(0, 1) !== '2') { return done(new ApiError(body. r.statusCode)); }
done();

@@ -515,6 +587,8 @@ }.bind(this));

url: this.apiUrl + '/clients/' + clientID,
qs: { access_token: accessToken }
headers: {
'Authorization': 'Bearer ' + accessToken,
}
}, function (err, r, body) {
if (err) return done(err);
if (r.statusCode.toString().substr(0, 1) !== '2') return done(new ApiError(body, r.statusCode));
if (err) { return done(err); }
if (r.statusCode.toString().substr(0, 1) !== '2') { return done(new ApiError(body, r.statusCode)); }
done(null, JSON.parse(body));

@@ -527,8 +601,10 @@ });

url: this.apiUrl + '/clients/?userId=' + userId,
qs: { access_token: accessToken }
headers: {
'Authorization': 'Bearer ' + accessToken,
}
}, function (err, r, body) {
if (err) return done(err);
if (r.statusCode.toString().substr(0, 1) !== '2') return done(new ApiError(body, r.statusCode));
if (err) { return done(err); }
if (r.statusCode.toString().substr(0, 1) !== '2') { return done(new ApiError(body, r.statusCode)); }
done(null, JSON.parse(body));
});
};

@@ -46,3 +46,3 @@ var request = require('request');

Client.prototype._getAccessToken = function(done){
Client.prototype.getAccessToken = function(done){
var self = this;

@@ -60,3 +60,3 @@

}, 1000 * 60 * 3); //~ 3 hours
done(null, token);

@@ -70,3 +70,3 @@ });

var callback = args[args.length - 1];
if (this.options.accessToken) {

@@ -76,3 +76,3 @@ api[m].apply(this, [this.options.accessToken].concat(args));

else {
this._getAccessToken(function (err, accessToken) {
this.getAccessToken(function (err, accessToken) {
if (err) return callback(err);

@@ -85,2 +85,2 @@ api[m].apply(this, [accessToken].concat(args));

module.exports = Client;
module.exports = Client;
{
"name": "auth0",
"version": "0.2.2",
"version": "0.3.1",
"description": "Client library for the Auth0 platform",
"main": "lib/index.js",
"scripts": {
"test": "mocha"
"test": "mocha test"
},

@@ -23,4 +23,5 @@ "repository": {

"devDependencies": {
"mocha": "~1.7.0",
"should": "~1.2.1"
"mocha": "~1.17.1",
"chai": "~1.9.0",
"nock": "~0.27.2"
},

@@ -27,0 +28,0 @@ "dependencies": {

@@ -98,2 +98,20 @@ Node.js client library for the Auth0 platform.

### api.getAccessToken(callback)
Retrieves an Access Token to make direct HTTP calls to Auth0 API.
```js
api.getAccessToken(function (err, token) {
if (err) {
console.log('Error fetching token: ' + err);
return;
}
// Do something with token
...
});
```
### api.updateUserMetadata(userId, metadata, callback)

@@ -100,0 +118,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