Skip to content

Commit

Permalink
feat: tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
hunger-programmer committed Feb 27, 2024
1 parent 45b2125 commit db2f2c1
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 28 deletions.
47 changes: 32 additions & 15 deletions public/sdkMethods/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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'});
Expand All @@ -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
Expand Down Expand Up @@ -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)

})
10 changes: 5 additions & 5 deletions public/utils.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
const showResults = (results)=>{
const showResults = (results) => {
document.querySelector('#main-wrapper').classList.add('md:mr-96')
document.querySelector('#results').classList.remove('hidden')

document.querySelector('#result-data').innerHTML = JSON.stringify(results, undefined, 2)
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(''),
Expand Down
4 changes: 2 additions & 2 deletions server/views/layouts/main.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root">
{{> nav }}
<div class="md:ml-64 bg-blueGray-50 md:mr-96" id="main-wrapper">
<div class="bg-pink-600 p-4 md:px-8 h-screen">
<div class="md:ml-64 bg-blueGray-50 md:mr-96" id="main-wrapper">
<div class="bg-pink-600 p-4 md:px-8 md:h-screen">
<div class="bg-white shadow-lg rounded">

{{{body}}}
Expand Down
2 changes: 1 addition & 1 deletion server/views/partials/methods/clearCachedAccessResult.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<pre>
<code class="language-javascript">
const identity = new Monetization({...})
const monetization = new Monetization({...})
- monetization.clearCachedAccessResult(productIds, userId);
</code>
</pre>
Expand Down
2 changes: 1 addition & 1 deletion server/views/partials/methods/hasAccess.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<pre>
<code class="language-javascript">
const identity = new Monetization({...})
const monetization = new Monetization({...})
- monetization.hasAccess(productIds, userId);
</code>
</pre>
Expand Down
6 changes: 3 additions & 3 deletions server/views/partials/methods/login.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
</div>

<div class="px-4">
<div class="inline-flex rounded-md shadow-sm mb-4" role="group">
<div class="inline-flex rounded-md shadow-sm mb-4 flex-col xl:flex-row" role="group">
<button type="button"
class="inline-flex items-center px-4 py-2 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-s-lg hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-2 focus:ring-blue-700 focus:text-blue-700 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:text-white dark:hover:bg-gray-700 dark:focus:ring-blue-500 dark:focus:text-white"
id="login-button">
Expand All @@ -182,11 +182,11 @@
</button>

<button
id="introspect-token"
id="simplified-login"
type="button"
class="inline-flex items-center px-4 py-2 text-sm font-medium text-gray-900 bg-white border-t border-b border-l border-gray-200 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-2 focus:ring-blue-700 focus:text-blue-700 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:hover:text-white dark:hover:bg-gray-700 dark:focus:ring-blue-500 dark:focus:text-white">
<i class="fa-solid fa-handshake-simple mr-2"></i>
Simplified login(TODO)
Simplified login
</button>

<button
Expand Down
2 changes: 1 addition & 1 deletion server/views/partials/results.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="fixed top-0 right-0 w-96 p-4 hidden" id="results">
<div class="md:fixed md:top-0 md:right-0 md:w-96 p-4 hidden" id="results">
<h2 class="font-bold">
Results
</h2>
Expand Down

0 comments on commit db2f2c1

Please sign in to comment.