mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
144 lines
2.9 KiB
TypeScript
144 lines
2.9 KiB
TypeScript
import * as auth0 from 'auth0';
|
|
|
|
const management = new auth0.ManagementClient({
|
|
token: '{YOUR_API_V2_TOKEN}',
|
|
domain: '{YOUR_ACCOUNT}.auth0.com'
|
|
});
|
|
|
|
const auth = new auth0.AuthenticationClient({
|
|
domain: '{YOUR_ACCOUNT}.auth0.com',
|
|
clientId: '{OPTIONAL_CLIENT_ID}',
|
|
clientSecret: '{OPTIONAL_CLIENT_SECRET}'
|
|
});
|
|
|
|
// Using a callback.
|
|
management.getUsers((err: Error, users: auth0.User[]) => {
|
|
if (err) {
|
|
// Handle error.
|
|
}
|
|
console.log(users);
|
|
});
|
|
|
|
// Using a Promise.
|
|
management
|
|
.getUsers()
|
|
.then((users) => {
|
|
console.log(users);
|
|
})
|
|
.catch((err) => {
|
|
// Handle the error.
|
|
});
|
|
|
|
// Using a callback.
|
|
management.getUser({id: 'user_id'},(err: Error, user: auth0.User) => {
|
|
if (err) {
|
|
// Handle error.
|
|
}
|
|
console.log(user);
|
|
});
|
|
|
|
// Using a Promise.
|
|
management
|
|
.getUser({id: 'user_id'})
|
|
.then((user) => {
|
|
console.log(user);
|
|
})
|
|
.catch((err) => {
|
|
// Handle the error.
|
|
});
|
|
|
|
// Using a callback.
|
|
management.deleteUser({id: 'user_id'},(err: Error) => {
|
|
if (err) {
|
|
// Handle error.
|
|
}
|
|
console.log('deleted');
|
|
});
|
|
|
|
// Using a Promise.
|
|
management
|
|
.deleteUser({id: 'user_id'})
|
|
.then(() => {
|
|
console.log('deleted');
|
|
})
|
|
.catch((err) => {
|
|
// Handle the error.
|
|
});
|
|
|
|
management
|
|
.createUser({
|
|
connection: 'My-Connection',
|
|
email: 'hi@me.co',
|
|
}).then((user) => {
|
|
console.log(user);
|
|
}).catch((err) => {
|
|
// Handle the error.
|
|
});
|
|
|
|
auth
|
|
.requestChangePasswordEmail({
|
|
connection: 'My-Connection',
|
|
email: 'hi@me.co',
|
|
}).then((response) => {
|
|
console.log(response);
|
|
}).catch((err) => {
|
|
// Handle the error.
|
|
});
|
|
|
|
|
|
// Update a user
|
|
management
|
|
.updateUser({id: "user_id"}, {"email": "hi@me.co"});
|
|
|
|
// Update a user using callback
|
|
management
|
|
.updateUser({id: "user_id"}, {"email": "hi@me.co"}, (err: Error, users: auth0.User) => {});
|
|
|
|
|
|
// Update user metadata
|
|
management
|
|
.updateUserMetadata({id: "user_id"}, {"key": "value"});
|
|
|
|
// Update user metadata using callback
|
|
management
|
|
.updateUserMetadata({id: "user_id"}, {"key": "value"}, (err: Error, users: auth0.User) => {});
|
|
|
|
|
|
// Update app metadata
|
|
management
|
|
.updateAppMetadata({id: "user_id"}, {"key": "value"});
|
|
|
|
// Update app metadata using callback
|
|
management
|
|
.updateAppMetadata({id: "user_id"}, {"key": "value"}, (err: Error, users: auth0.User) => {});
|
|
|
|
|
|
management.getUsersByEmail('email@address.com', (err, users) => {
|
|
console.log(users);
|
|
});
|
|
|
|
management.getUsersByEmail('email@address.com').then((users) => {
|
|
console.log(users);
|
|
});
|
|
|
|
// Using different client settings.
|
|
|
|
const retryableManagementClient = new auth0.ManagementClient({
|
|
clientId: '',
|
|
clientSecret: '',
|
|
domain: 'xxx.auth0.com',
|
|
retry: {
|
|
enabled : true
|
|
}
|
|
});
|
|
|
|
management.createPasswordChangeTicket({
|
|
connection_id: 'con_id',
|
|
email: 'test@me.co',
|
|
new_password: 'password',
|
|
result_url: 'https://www.google.com/',
|
|
ttl_sec: 86400,
|
|
}, (err: Error, data) => {
|
|
console.log(data.ticket);
|
|
});
|