-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
38 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<% if (email) { %> | ||
<script> | ||
window.onload = function() { | ||
// If the user is logged in, send the email back to the parent frame | ||
window.parent.postMessage({ action: 'loggedIn', email: '<%= email %>', test: 'testing' }, '*'); | ||
}; | ||
</script> | ||
<% } else { %> | ||
Not logged in | ||
<% } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,33 @@ | ||
<%- include(commonPath + '/header.ejs') %> | ||
|
||
<div class="container mx-auto py-8"> | ||
<h1 class="text-3xl font-bold mb-4 text-center">🚧 Single Sign-On Demo</h1> | ||
<div class="text-center"> | ||
<button id="signInButton" class="bg-blue-500 text-white font-bold py-2 px-4 rounded-full inline-block">Sign In</button> | ||
</div> | ||
<h1 class="text-3xl font-bold mb-4 text-center">🚧 Single Sign-On Demo</h1> | ||
<div class="text-center"> | ||
<button id="signInButton" class="bg-blue-500 text-white font-bold py-2 px-4 rounded-full inline-block">Sign In</button> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
document.getElementById('signInButton').addEventListener('click', function() { | ||
const win = window.open('<%= protocol %>://<%= domainC %>/single-sign-on/login', 'Login to SSO', 'width=500,height=500'); | ||
window.onload = function() { | ||
window.addEventListener('message', function(event) { | ||
// Ensure the postMessage is coming from domainC | ||
if (event.origin !== '<%= protocol %>://<%= domainC %>') return; | ||
// Expected structure of event.data: { action: 'login', email: '[email protected]' } | ||
if (event.data.action === 'login') { | ||
// Set the cookie for domainC here using fetch or other methods. | ||
// Redirect to profile or another route as needed. | ||
document.cookie = `email=${event.data.email}; max-age=900000`; | ||
if (event.data.action === 'loggedIn') { | ||
// Set the localemail cookie for domainA | ||
document.cookie = `localemail=${event.data.email}; path=/; max-age=900000`; | ||
window.location.href = '/single-sign-on/profile'; | ||
} | ||
}, false); | ||
} | ||
document.getElementById('signInButton').addEventListener('click', function() { | ||
const win = window.open('<%= protocol %>://<%= domainC %>/single-sign-on/login', 'Login to SSO', 'width=500,height=500'); | ||
}); | ||
</script> | ||
|
||
<!-- Hidden iframe to check login status on domainC --> | ||
<iframe id="checkLoginFrame" src="<%= protocol %>://<%= domainC %>/single-sign-on/check-login-status" style="display:none;"></iframe> | ||
|
||
<%- include(commonPath + '/footer.ejs') %> |