Compare commits
2 Commits
5d1bad39f2
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f403e53ce | |||
| c7af13f749 |
@@ -1 +1,2 @@
|
||||
JWT_SECRET=your_jwt_secret_key_here
|
||||
JWT_SECRET=your_jwt_secret_key_here
|
||||
SSO_URL=sso_url_here
|
||||
@@ -4,7 +4,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
if (ssoLoginButton) {
|
||||
ssoLoginButton.addEventListener('click', () => {
|
||||
// Open the SSO provider's login page in a popup
|
||||
const ssoUrl = 'https://sso.hmac.kr/'; // Real SSO provider URL
|
||||
|
||||
const popupWidth = 500;
|
||||
const popupHeight = 600;
|
||||
const left = (screen.width / 2) - (popupWidth / 2);
|
||||
@@ -19,8 +19,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
// Listen for a message from the popup
|
||||
window.addEventListener('message', (event) => {
|
||||
// IMPORTANT: Verify the origin of the message for security
|
||||
if (event.origin !== 'https://sso.hmac.kr') {
|
||||
console.warn('Received message from untrusted origin:', event.origin);
|
||||
const ssoOrigin = new URL(ssoUrl).origin;
|
||||
if (event.origin !== ssoOrigin) {
|
||||
console.warn(`Received message from untrusted origin: ${event.origin}, expected: ${ssoOrigin}`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,10 @@ const router = express.Router();
|
||||
// GET home page
|
||||
router.get('/', (req, res, next) => {
|
||||
// The ssoHandler middleware has already attached the user to res.locals
|
||||
res.render('index', { user: res.locals.user });
|
||||
res.render('index', {
|
||||
user: res.locals.user,
|
||||
ssoUrl: process.env.SSO_URL // Pass SSO_URL to the template
|
||||
});
|
||||
});
|
||||
|
||||
// GET logout
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Express SSO Login Demo</title>
|
||||
<title>ExpressJS SSO Login Demo</title>
|
||||
<link rel="stylesheet" href="/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
@@ -69,6 +69,10 @@
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Pass the SSO URL from the server (via the template) to the client-side JS
|
||||
const ssoUrl = '<%= ssoUrl %>';
|
||||
</script>
|
||||
<script src="/js/sso.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user