node-auth0
Node.js client library for the Auth0 platform.
Installation
npm install auth0@2.0.0-alpha.5
Usage
Initialize your client class with an API v2 token (you can generate one here).
var token = '{YOUR_API_V2_TOKEN}';
var auth0 = require('auth0')({
token: token
});
By default the code assumes your account is running in the US West region. If you are running in Europe you can specify:
var token = '{YOUR_API_V2_TOKEN}';
var auth0 = require('auth0')({
token: token,
region: 'eu'
});
Alternatively you can just set the domain:
var token = '{YOUR_API_V2_TOKEN}';
var auth0 = require('auth0')({
token: token,
domain: 'login.eu.auth0.com'
});
Promises and Callbacks
Be aware that all methods can be used with Promises or callbacks. However, when a callback is provided, no Promise will be returned.
auth0.getUsers(function (err, users) {
if (err) {
}
console.log(users);
});
auth0
.getUsers()
.then(function (users) {
console.log(users);
})
.catch(function (err) {
});
Clients
Clients represent applications. You can learn more about this in the Applications section of the documentation.
Get all clients
auth0.getClients(function (err, clients) {
console.log(clients.length);
});
auth0.clients.getAll(function (err, clients) {
console.log(clients.length);
});
Create a client
auth0.createClient(data, function (err) {
if (err) {
}
});
auth0.clients.create(data, function (err) {
if (err) {
}
});
Get a client
auth0.getClient({ client_id: CLIENT_ID }, function (err, client) {
if (err) {
}
console.log(client);
});
auth0.clients.get({ client_id: CLIENT_ID }, function (err, client) {
if (err) {
}
console.log(client);
});
Delete a client
auth0.deleteClient({ client_id: CLIENT_ID }, function (err) {
if (err) {
}
});
auth0.clients.delete({ client_id: CLIENT_ID }, function (err) {
if (err) {
}
});
Update a client
var data = { name: 'newClientName' };
var params = { client_id: CLIENT_ID };
auth0.updateClient(params, data, function (err, client) {
if (err) {
}
console.log(client.name);
});
auth0.clients.update(params, data, function (err, client) {
if (err) {
}
console.log(client.name);
});
Connections
Connections represent the relationships between Auth0 and each one of the Identity Providers.
Get all connections
auth0.getConnections(function (err, connections) {
console.log(connections.length);
});
auth0.connections.getAll(function (err, connections) {
console.log(connections.length);
});
Create a connection
auth0.createConnection(data, function (err) {
if (err) {
}
});
auth0.connections.create(data, function (err) {
if (err) {
}
});
Get a connection
auth0.getConnection({ id: CONNECTION_ID }, function (err, connection) {
if (err) {
}
console.log(connection);
});
auth0.connections.get({ id: CONNECTION_ID }, function (err, connection) {
if (err) {
}
console.log(connection);
});
Delete a connection
auth0.deleteConnection({ id: CONNECTION_ID }, function (err) {
if (err) {
}
});
auth0.connections.delete({ id: CONNECTION_ID }, function (err) {
if (err) {
}
});
Update a connection
var data = { name: 'newConnectionName' };
var params = { id: CONNECTION_ID };
auth0.updateConnection(params, data, function (err, connection) {
if (err) {
}
console.log(connection.name);
});
auth0.connections.update(params, data, function (err, connection) {
if (err) {
}
console.log(connection.name);
});
Device Credentials
Managing of Device Credentials with Auth0 SDK.
List device credentials
auth0.getDeviceCredentials(function (err, credentials) {
console.log(credentials.length);
});
auth0.deviceCredentials.getAll(function (err, credentials) {
console.log(credentials.length);
});
Create device public key
auth0.createConnection(data, function (err) {
if (err) {
}
});
auth0.deviceCredentials.create(data, function (err) {
if (err) {
}
});
Delete a device credential
var params = { id: CREDENTIAL_ID };
auth0.deleteDeviceCredential(params, function (err) {
if (err) {
}
});
auth0.deviceCredentials.delete(params, function (err) {
if (err) {
}
});
Rules
Rules are code snippets written in JavaScript that are executed as part of the authentication pipeline in Auth0. Learn more about them in the Rules section of the documentation.
Get all rules
auth0.getRules(function (err, rules) {
console.log(rules.length);
});
auth0.rules.getAll(function (err, rules) {
console.log(rules.length);
});
Create a rule
auth0.createRule(data, function (err) {
if (err) {
}
});
auth0.rules.create(data, function (err) {
if (err) {
}
});
Get a rule
auth0.getRule({ id: RULE_ID }, function (err, rule) {
if (err) {
}
console.log(rule);
});
auth0.rules.get({ id: RULE_ID }, function (err, rule) {
if (err) {
}
console.log(rule);
});
Delete a rule
auth0.deleteRule({ id: RULE_ID }, function (err) {
if (err) {
}
});
auth0.rules.delete({ id: RULE_ID }, function (err) {
if (err) {
}
});
Update a rule
var data = { name: 'New name' };
var params = { id: RULE_ID };
auth0.updateRule(params, data, function (err, rule) {
if (err) {
}
console.log(rule.name);
});
auth0.rules.update(params, data, function (err, rule) {
if (err) {
}
console.log(rule.name);
});
Users
Performing CRUD operations on the Users endpoint.
List or search users
This method takes an optional object as first argument that may be used to specify pagination settings and the search query.
var params = {
per_page: 10,
page: 2
};
auth0.getUsers(params, function (err, users) {
console.log(users.length);
});
auth0.users.getAll(function (err, users) {
console.log(users.length);
});
Create a user
auth0.createUser(data, function (err) {
if (err) {
}
});
auth0.users.create(data, function (err) {
if (err) {
}
});
Get a user
auth0.getUser({ id: USER_ID }, function (err, user) {
console.log(user);
});
auth0.users.get({ id: USER_ID }, function (err, user) {
console.log(user);
});
Delete all users
auth0.deleteAllUsers(function (err) {
if (err) {
}
});
auth0.users.deleteAll(function (err) {
if (err) {
}
});
Delete a user
auth0.deleteUser({ id: USER_ID }, function (err) {
if (err) {
}
});
auth0.users.delete({ id: USER_ID }, function (err) {
if (err) {
}
});
Update a user
var params = { id: USER_ID };
auth0.updateUser(params, data, function (err, user) {
if (err) {
}
console.log(user);
});
auth0.users.update(params, data, function (err, user) {
if (err) {
}
console.log(user);
});
Update user and app metadata
var params = { id: USER_ID };
var data = {
app_metadata: {
foo: 'bar'
},
user_metadata: {
address: '123th Node.js Street'
}
};
auth0.updateUser(params, data, function (err, user) {
if (err) {
}
console.log(user);
});
auth0.users.update(params, data, function (err, user) {
if (err) {
}
console.log(user);
});
Blacklisted Tokens
Managing Blacklisted tokens with the SDK.
Get all blacklisted tokens
auth0.getBlacklistedTokens(function (err, tokens) {
console.log(tokens.length);
});
auth0.blacklistedTokens.getAll(function (err, tokens) {
console.log(tokens.length);
});
Blacklist a token
var token = {
aud: 'aud',
jti: 'jti'
};
auth0.blacklistToken(token, function (err) {
if (err) {
}
});
auth0.blacklistedTokens.add(token, function (err) {
if (err) {
}
});
Email Provider
Configuring the Email Provider.
Get the email provider
auth0.getEmailProvider(function (err, provider) {
console.log(provider.length);
});
auth0.emailProvider.get(function (err, provider) {
console.log(provider);
});
Configure the email provider
auth0.configureEmailProvider(data, function (err) {
if (err) {
}
});
auth0.emailProvider.configure(data, function (err) {
if (err) {
}
});
Delete the email provider
auth0.deleteEmailProvider(function (err) {
if (err) {
}
});
auth0.emailProvider.delete(function (err) {
if (err) {
}
});
Update the email provider
auth0.updateEmailProvider(data, function (err, provider) {
if (err) {
}
console.log(provider);
});
auth0.emailProvider.update(function (err, provider) {
if (err) {
}
console.log(provider);
});
Authentication
This library can be used to access Auth0's API v2. To authenticate users use the passport strategy.
Examples
Check out the examples folder.
Documentation
For more information about auth0 contact our documentation page.
What is Auth0?
Auth0 helps you to:
- Add authentication with multiple authentication sources, either social like Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce, amont others, or enterprise identity systems like Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider.
- Add authentication through more traditional username/password databases.
- Add support for linking different user accounts with the same user.
- Support for generating signed Json Web Tokens to call your APIs and flow the user identity securely.
- Analytics of how, when and where users are logging in.
- Pull data from other sources and add it to the user profile, through JavaScript rules.
Create a free Auth0 Account
- Go to Auth0 and click Sign Up.
- Use Google, GitHub or Microsoft Account to login.
Issue Reporting
If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
Author
Auth0
License
This project is licensed under the MIT license. See the LICENSE file for more info.