Created
May 30, 2019 11:37
-
-
Save Tanver-Hasan/f47219570f6d735f2d716da4ce898076 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
<title>Sample Application 3</title> | |
</head> | |
<body> | |
<h1>Application 3</h1> | |
<H1>A very simple single page application</H1> | |
<p>Results of Login will be displayed below:</p> | |
<div id="root"></div> | |
<br /> | |
<div id="result"></div> | |
<script src="https://cdn.auth0.com/js/lock/11.14.1/lock.min.js"></script> | |
<script type="text/javascript"> | |
var lockOptions = { | |
container: "root", | |
theme: { | |
logo: "https://www.okura.nl/app/uploads/2019/05/logo-hoa-gingko-1.png" | |
}, | |
auth: { | |
// usernameStyle: 'username', | |
redirect: false, | |
audience: "http://localhost:5000", | |
responseType: "token id_token", | |
params: { | |
scope: "openid email profile" | |
} | |
} | |
}; | |
//Set up the lock login widget | |
var lock = new Auth0Lock( | |
"[CLient id]", | |
"[Domain]", | |
lockOptions | |
); | |
lock.on("authenticated", function(authResult) { | |
lock.getProfile(authResult.accessToken, function(error, profile) { | |
if (error) { | |
console.error("Cannot get user :(", error); | |
return; | |
} | |
localStorage.setItem("accessToken", authResult.accessToken); | |
localStorage.setItem("profile", JSON.stringify(profile)); | |
//Display the results of login on the page | |
document.getElementById("result").innerHTML = | |
"Login Succeeded: " + | |
"<br><br>" + | |
"id_token: " + | |
authResult.idToken + | |
"<br><br>" + | |
" user profile:" + | |
profile.name + | |
" < br > " + | |
"user id: " + | |
profile.sub + | |
"<br><br>" + | |
"access token: " + | |
authResult.accessToken + | |
"<br>"; | |
}); | |
}); | |
var onError = function(err) { | |
console.log("There was an error", err); | |
}; | |
lock.on("authorization_error", onError); | |
lock.on("unrecoverable_error", onError); | |
lock.show(); | |
//When the user presses login button, trigger login widget | |
// var signin = function () { | |
// lock.show(); | |
// }; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment