This is a small app that demonstrates how easy it is to login users by using Lock Widget.
You can read a quickstart guide for this sample here.
Rename auth0-variables.js.example to auth0-variables.js and make sure that you have both the Client ID and Client Secretin it. You can find that information in the settings section of your Auth0 Client. Also, make sure to add the callback URL (http://localhost:3000/ if you are testing locally) in the Allowed Callback URLs section, as explained here
In order to run the example you need to just start a server. What we suggest is doing the following:
- Install node
- run
npm install -g serve - run
servein the directory of the project.
Go to http://localhost:3000 and you'll see the app running :).
<!-- ===== ./index.html ===== -->
<head>
...
<!-- Auth0 lock script -->
<script src="//cdn.auth0.com/js/lock/10.3.0/lock.min.js"></script>
...
</head>$(document).ready(function() {
var lock = null;
lock = new Auth0Lock(AUTH0_CLIENT_ID, AUTH0_DOMAIN, {
auth: {
params: { scope: 'openid email' } //Details: https://auth0.com/docs/scopes
}
});
$('.btn-login').click(function(e) {
e.preventDefault();
lock.show();
});
lock.on("authenticated", function(authResult) {
lock.getProfile(authResult.idToken, function(error, profile) {
if (error) {
// Handle error
return;
}
localStorage.setItem('id_token', authResult.idToken);
});
});
});