Skip to content

Instantly share code, notes, and snippets.

@arcseldon
Created April 27, 2018 07:58
Show Gist options
  • Select an option

  • Save arcseldon/fd9407273d591a94989be8529a88f59d to your computer and use it in GitHub Desktop.

Select an option

Save arcseldon/fd9407273d591a94989be8529a88f59d to your computer and use it in GitHub Desktop.

Revisions

  1. arcseldon created this gist Apr 27, 2018.
    61 changes: 61 additions & 0 deletions user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    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");
    }
    });
    }