-
Notifications
You must be signed in to change notification settings - Fork 6
/
get_user.js
27 lines (27 loc) · 1.3 KB
/
get_user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function getByEmail (email, callback) {
// to use Auth0 search API, first we need a management API `access_token`
var tools = require('[email protected]');
tools.managementApi.getClient({domain: configuration.Domain, clientId: configuration.Client_ID, clientSecret: configuration.Client_Secret})
.then(function(client) {
var params = {
q: 'email:"' + email + '" AND identities.connection:"' + configuration.Connection + '" !app_metadata.migration_complete:true'
};
client.users.getAll(params, function (err, users){
if (err) return callback(err);
else if(Array.isArray(users) && users.length > 0) {
var profile = {};
var openidProfile = users[0];
profile.name = openidProfile.name || '';
profile.nickname = openidProfile.nickname || '';
profile.email = openidProfile.email;
profile.email_verified = openidProfile.email_verified || false;
profile.user_id = openidProfile.user_id.replace(/^auth0/,configuration.Domain);
profile.user_metadata = openidProfile.user_metadata || {};
profile.app_metadata = openidProfile.app_metadata || {};
return callback(null, profile);
} else {
return callback();
}
});
});
}