Created
October 22, 2017 21:34
-
-
Save abbaspour/c4fdb8948eab0c38e826bff6ff9c7666 to your computer and use it in GitHub Desktop.
Auth0 Migration Custom Database - Login Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function login (username, password, callback){ | |
request({ | |
url: 'https://' + configuration.Domain + '/oauth/token', | |
method: 'POST', | |
form: { | |
grant_type: 'password', | |
scope: 'openid', // todo: add name to scope | |
audience: configuration.Audience, | |
client_id: configuration.Client_ID, | |
client_secret: configuration.Client_Secret, | |
username: username, | |
password: password | |
}, | |
headers: {'content-type' : 'application/json'}, | |
json: true | |
}, function(error, response, body){ | |
if(error) { | |
callback(error); | |
} else { | |
if(response.statusCode !== 200){ | |
callback(); | |
} else { | |
var id_token = jwt.decode(body.id_token); // jwt_decode | |
callback(null, { | |
user_id : id_token.name, | |
username: id_token.name, | |
email: id_token.email, | |
email_verified: id_token.email_verified, | |
nickname: id_token.nickname | |
}); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment