Skip to content

Instantly share code, notes, and snippets.

@arcseldon
Created Apr 27, 2018
Embed
What would you like to do?
Sample that demonstrates calling check session
extends layout
block content
br
.w3-container
.w3-card-4.w3-center(style="padding: 15px;")
img(src=user.picture)
p Welcome #{user.nickname}
h2 User Profile
pre #{userProfile}
div
button(id="check-session") Check Session
script.
//- $(function() {
//- const auth0WebAuth = new auth0.WebAuth({
//- domain: '#{env.AUTH0_DOMAIN}',
//- clientID: '#{env.AUTH0_CLIENT_ID}',
//- redirectUri: '#{env.AUTH0_CALLBACK_URL}',
//- responseType: 'id_token token',
//- scope: 'openid email'
//- });
//- checkSession();
//- }
const auth0WebAuth = new auth0.WebAuth({
domain: '#{env.AUTH0_DOMAIN}',
clientID: '#{env.AUTH0_CLIENT_ID}',
redirectUri: '#{env.AUTH0_CALLBACK_URL}',
responseType: 'id_token token',
scope: 'openid email'
});
$('#check-session').on('click', function(e) {
e.preventDefault();
//- window.location = "http://app1.demonstration.site:3000/api/session";
checkSession();
});
// periodically check for SSO status
//- setInterval(function() {
//- checkSession();
//- }, 120000);
function checkSession () {
auth0WebAuth.checkSession({
//- responseType: 'token id_token',
responseType: 'token',
//- responseType: 'code',
timeout: 5000,
usePostMessage: true
}, function (err, result) {
console.log(JSON.stringify(result));
if (err) {
alert(`Could not get a new token using silent authentication (${err.error}). Opening login page...`);
} else {
alert("all good");
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment