From db2f2c1f3e02a5e82c51dd05448a2447772516f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20W=C3=B3jcik?= Date: Tue, 27 Feb 2024 18:36:13 +0100 Subject: [PATCH] feat: tmp --- public/sdkMethods/login.js | 47 +++++++++++++------ public/utils.js | 10 ++-- server/views/layouts/main.hbs | 4 +- .../methods/clearCachedAccessResult.hbs | 2 +- server/views/partials/methods/hasAccess.hbs | 2 +- server/views/partials/methods/login.hbs | 6 +-- server/views/partials/results.hbs | 2 +- 7 files changed, 45 insertions(+), 28 deletions(-) diff --git a/public/sdkMethods/login.js b/public/sdkMethods/login.js index 8a65573..abcc1c2 100644 --- a/public/sdkMethods/login.js +++ b/public/sdkMethods/login.js @@ -11,21 +11,21 @@ document.addEventListener('DOMContentLoaded', async () => { locale: document.querySelector('#locale'), } + const preferPopup = elements.usePopup.checked; + const state = generateState(preferPopup); + + const getAcrValues = () => { + const checkedAcr = elements.acrValues; + const acrs = []; + for (let acr of checkedAcr) { + acrs.push(acr.value); + } + return acrs.join(' '); + }; + elements.loginButton.addEventListener('click', (event) => { event.preventDefault(); - const preferPopup = elements.usePopup.checked; - const state = generateState(preferPopup); - - const getAcrValues = () => { - const checkedAcr = elements.acrValues; - const acrs = []; - for (let acr of checkedAcr) { - acrs.push(acr.value); - } - return acrs.join(' '); - }; - const popup = window.identity.login({ state, scope: 'openid profile', @@ -71,10 +71,8 @@ document.addEventListener('DOMContentLoaded', async () => { showResults(err) } } - document.querySelector('#update-login-sso').addEventListener('click', updateIsLoggedInToSso) - async function updateIsLoggedInToSdk() { try { const response = await fetch('/isloggedin', {credentials: 'include'}); @@ -89,7 +87,6 @@ document.addEventListener('DOMContentLoaded', async () => { showResults(`Error: ` + JSON.stringify(error, undefined, 2)) } } - document.querySelector('#update-sdk-login').addEventListener('click', updateIsLoggedInToSdk) //fetch user on load @@ -133,4 +130,24 @@ document.addEventListener('DOMContentLoaded', async () => { } document.querySelector('#introspect-token').addEventListener('click', introspectToken) + //Simplified login + const triggerSimplifiedLogin = ()=>{ + try{ + window.identity.showSimplifiedLoginWidget({ + state, + scope: 'openid profile', + acrValues: getAcrValues(), + preferPopup, + newFlow: elements.startNewFlow.checked, + loginHint: elements.preferedEmail.value, + oneStepLogin: elements.oneStepLogin.checked, + locale: elements.locale.value, + }); + }catch (error){ + showResults("Error: " + error) + } + + } + document.querySelector('#simplified-login').addEventListener('click', triggerSimplifiedLogin) + }) diff --git a/public/utils.js b/public/utils.js index 9ca6e49..1c92da4 100644 --- a/public/utils.js +++ b/public/utils.js @@ -1,4 +1,4 @@ -const showResults = (results)=>{ +const showResults = (results) => { document.querySelector('#main-wrapper').classList.add('md:mr-96') document.querySelector('#results').classList.remove('hidden') @@ -6,16 +6,16 @@ const showResults = (results)=>{ document.querySelector('#result-data-input').value = JSON.stringify(results, undefined, 2) } -window.showResults=showResults; +window.showResults = showResults; -const hideResults = ()=>{ +const hideResults = () => { document.querySelector('#main-wrapper').classList.remove('md:mr-96') document.querySelector('#results').classList.add('hidden') } -window.hideResults=hideResults; +window.hideResults = hideResults; -const generateState = (preferPopup = false) =>{ +const generateState = (preferPopup = false) => { const char = () => Math.floor((Math.random() * (122 - 97)) + 97); const stateObj = { id: Array.from({length: 20}, () => String.fromCharCode(char())).join(''), diff --git a/server/views/layouts/main.hbs b/server/views/layouts/main.hbs index 9a7e487..7f4a137 100644 --- a/server/views/layouts/main.hbs +++ b/server/views/layouts/main.hbs @@ -38,8 +38,8 @@
{{> nav }} -
-
+
+
{{{body}}} diff --git a/server/views/partials/methods/clearCachedAccessResult.hbs b/server/views/partials/methods/clearCachedAccessResult.hbs index 0bfa716..d3f821a 100644 --- a/server/views/partials/methods/clearCachedAccessResult.hbs +++ b/server/views/partials/methods/clearCachedAccessResult.hbs @@ -9,7 +9,7 @@
         
-const identity = new Monetization({...})
+const monetization = new Monetization({...})
 - monetization.clearCachedAccessResult(productIds, userId);
         
     
diff --git a/server/views/partials/methods/hasAccess.hbs b/server/views/partials/methods/hasAccess.hbs index 75b29e0..e5ed96a 100644 --- a/server/views/partials/methods/hasAccess.hbs +++ b/server/views/partials/methods/hasAccess.hbs @@ -9,7 +9,7 @@
         
-const identity = new Monetization({...})
+const monetization = new Monetization({...})
 - monetization.hasAccess(productIds, userId);
         
     
diff --git a/server/views/partials/methods/login.hbs b/server/views/partials/methods/login.hbs index 2b743fe..6456e23 100644 --- a/server/views/partials/methods/login.hbs +++ b/server/views/partials/methods/login.hbs @@ -157,7 +157,7 @@
-
+