Skip to content

Commit

Permalink
Merge pull request #27 from rtCamp/feature/adding-gsi-demo
Browse files Browse the repository at this point in the history
Implement Legacy GSI Demo
  • Loading branch information
fellyph authored Feb 2, 2024
2 parents bbad002 + 4f6cc6b commit df1ecb4
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ domain-b-background=bg-blue-100
domain-c=localhost # domain-ccc.com
domain-c-background=bg-red-100
port=8080 # port to listen on
google-client-id= # google client id
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ app.use((req, res, next) => {
res.locals.domainA = process.env['domain-a'];
res.locals.domainB = process.env['domain-b'];
res.locals.domainC = process.env['domain-c'];
res.locals.googleClientId = process.env['google-client-id'];
res.locals.port = process.env.port;
res.locals.isPortPresent = req.get('host').includes(':');
res.locals.currentDomain = req.get( 'host' );
Expand Down Expand Up @@ -66,6 +67,7 @@ const scenarios = [
'analytics',
'embedded-video',
'payment-gateway',
'gsi'
];
scenarios.forEach(scenario => {
const scenarioRoutes = require(`./src/scenarios/${scenario}/routes`);
Expand Down
4 changes: 4 additions & 0 deletions public/assets/styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,10 @@ video {
display: grid;
}

.hidden {
display: none;
}

.aspect-square {
aspect-ratio: 1 / 1;
}
Expand Down
1 change: 1 addition & 0 deletions src/common/header.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap" rel="stylesheet">
<meta name="google-signin-client_id" content="<%= googleClientId %>">

<link rel="stylesheet" href="/assets/styles/style.css">
<script src="/assets/js/main.js"></script>
Expand Down
1 change: 1 addition & 0 deletions src/common/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<%= renderCard('Single Sign-On', '🔐', '/single-sign-on','Using third-party providers to creating a login session') %>
<%= renderCard('Payment Gateway', '💳', '/payment-gateway','Payment flow simulation with credit card') %>
<%= renderCard('CHIPS', '🍪', '/chips','Using CHIPS to solve tracking issues across third-party applications') %>
<%= renderCard('Legacy GSI', '🔐', '/gsi','Testing the Legacy GSI') %>
</div>
</div>

Expand Down
31 changes: 31 additions & 0 deletions src/scenarios/gsi/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<%- include(commonPath + '/header.ejs') %>

<div class="container mx-auto py-8">
<h1 class="text-3xl font-bold mb-4 text-center">Legacy Google Sign-in</h1>
<p class="text-lg font-bold mb-4 text-center">Please login to test this demo.</p>
<div class="flex justify-center">
<div class="g-signin2" data-onsuccess="onSignIn"></div>
<button id="signout-btn" class="hidden ml-4 bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" onclick="signOut()">Sign Out</button>
</div>
<div id="status" class="text-center text-lg mt-4"></div>
</div>

<script>
const statusMessage = document.getElementById('status');
const signoutBtn = document.getElementById('signout-btn');
function onSignIn(googleUser) {
signoutBtn.classList.remove('hidden');
const profile = googleUser.getBasicProfile();
statusMessage.textContent = 'Hello ' + profile.getName() + '!';
}
function signOut() {
const auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
statusMessage.textContent = '';
});
}
</script>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<%- include(commonPath + '/footer.ejs') %>
12 changes: 12 additions & 0 deletions src/scenarios/gsi/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const express = require('express');
const path = require('path');
const router = express.Router();

router.get('/', (req, res) => {
// Send the default page
res.render(path.join(__dirname,'index'), {
title: 'Legacy GSI'
});
});

module.exports = router;

0 comments on commit df1ecb4

Please sign in to comment.