From bc292b44b2b89ff5807da6ab7c4ba12838ee02ff Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 10 Aug 2018 21:11:37 +0200 Subject: [PATCH] Login and Singnup with Auth0 ready --- Dashboard.js | 2 +- TopSpace/Login.js | 63 +++++++++++++++++++++++++++++++++++++++++------ index.html | 5 +++- 3 files changed, 60 insertions(+), 10 deletions(-) diff --git a/Dashboard.js b/Dashboard.js index 1f1474526..a9d5a7a35 100644 --- a/Dashboard.js +++ b/Dashboard.js @@ -20,7 +20,7 @@ function newDashboard() { start: start }; - const DEBUG_START_UP_DELAY = 0 //3000; // This is a waiting time in case there is a need to debug the very first steps of initialization, to be able to hit F12 on time. + const DEBUG_START_UP_DELAY = 0; //3000; // This is a waiting time in case there is a need to debug the very first steps of initialization, to be able to hit F12 on time. return thisObject; diff --git a/TopSpace/Login.js b/TopSpace/Login.js index c31548c65..e205b0223 100644 --- a/TopSpace/Login.js +++ b/TopSpace/Login.js @@ -21,29 +21,64 @@ function newLogin() { container.isDraggeable = false; container.isClickeable = true; - const LOGIN_URL = "https://advancedalgos1.eu.auth0.com/login?state=HQmR_JEnoSYS9Zz0nkCzW_zALsRJXjoQ&client=GReymhOiUQuLhDEwxlLu6PMDIa6mjVQQ&protocol=oauth2&response_type=token%20id_token&redirect_uri=https%3A%2F%2F" + window.location.host + "%2F%23&scope=openid&audience=https%3A%2F%2Fadvancedalgos1.eu.auth0.com%2Fuserinfo&nonce=7LZ5hOd6D3jFdNdtDvEqNOyOR3nZXw5A&auth0Client=eyJuYW1lIjoiYXV0aDAuanMiLCJ2ZXJzaW9uIjoiOS41LjEifQ%3D%3D" + const AUTH0_CLIENT_ID = 'WQTnXt20a0t2WGl64mEcOyP4Ippo37nB'; + const AUTH0_DOMAIN = 'advancedalgos.eu.auth0.com'; + + const LOGIN_URL = "https://" + AUTH0_DOMAIN + "/authorize" + + "?state=" + + "&client_id=" + AUTH0_CLIENT_ID + + "&response_type=id_token" + + "&redirect_uri=" + location.href + "index.html" + + "&scope=openid" + + "&nonce=CALCULATESOMENONCE"; + const LOGOUT_URL = "/"; let currentURL; let currentLabel; - let sharedStatus; + let Auth0; + let userAuthorization; return thisObject; function initialize() { + let parameters = { + domain: 'advancedalgos.eu.auth0.com', + redirectUri: window.location.href, + clientID: 'WQTnXt20a0t2WGl64mEcOyP4Ippo37nB' + }; - if (window.USER_LOGGED_IN === "") { + Auth0 = new auth0.WebAuth(parameters); - currentLabel = "Login"; - currentURL = LOGIN_URL; + userAuthorization = window.location.hash.substr(1); // What comes after the # on the URL. + + if (userAuthorization === "") { + + currentLabel = "Login / Signup"; } else { - currentLabel = "Logout"; - currentURL = LOGOUT_URL; + console.log(userAuthorization); + Auth0.parseHash({ hash: window.location.hash }, function (err, authResult) { + if (err) { + return console.log(err); + } + + console.log(err); + console.log(authResult); + + // The contents of authResult depend on which authentication parameters were used. + // It can include the following: + // authResult.accessToken - access token for the API specified by `audience` + // authResult.expiresIn - string with the access token's expiration time in seconds + // authResult.idToken - ID token JWT containing user profile information + + currentLabel = "Logout"; + + }); } thisObject.container.eventHandler.listenToEvent("onMouseClick", onClick); @@ -51,8 +86,20 @@ function newLogin() { function onClick() { - window.location.href = currentURL; + if (userAuthorization === "") { + /* Goes for a login / signup */ + + Auth0.authorize({ + scope: 'openid profile', + responseType: 'id_token' + }); + + } else { + + /* Goes for a logout */ + + } } function getContainer(point) { diff --git a/index.html b/index.html index 035c7d6a6..693ec1db4 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,8 @@ Advanced Algos - + + @@ -15,6 +16,8 @@