sso url 하드코딩 수정

This commit is contained in:
kyy
2026-01-16 14:01:01 +09:00
parent c7af13f749
commit 3f403e53ce
4 changed files with 14 additions and 5 deletions

View File

@@ -1 +1,2 @@
JWT_SECRET=your_jwt_secret_key_here JWT_SECRET=your_jwt_secret_key_here
SSO_URL=sso_url_here

View File

@@ -4,7 +4,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (ssoLoginButton) { if (ssoLoginButton) {
ssoLoginButton.addEventListener('click', () => { ssoLoginButton.addEventListener('click', () => {
// Open the SSO provider's login page in a popup // Open the SSO provider's login page in a popup
const ssoUrl = 'https://sso.hmac.kr/'; // Real SSO provider URL
const popupWidth = 500; const popupWidth = 500;
const popupHeight = 600; const popupHeight = 600;
const left = (screen.width / 2) - (popupWidth / 2); const left = (screen.width / 2) - (popupWidth / 2);
@@ -19,8 +19,9 @@ document.addEventListener('DOMContentLoaded', () => {
// Listen for a message from the popup // Listen for a message from the popup
window.addEventListener('message', (event) => { window.addEventListener('message', (event) => {
// IMPORTANT: Verify the origin of the message for security // IMPORTANT: Verify the origin of the message for security
if (event.origin !== 'https://sso.hmac.kr') { const ssoOrigin = new URL(ssoUrl).origin;
console.warn('Received message from untrusted origin:', event.origin); if (event.origin !== ssoOrigin) {
console.warn(`Received message from untrusted origin: ${event.origin}, expected: ${ssoOrigin}`);
return; return;
} }

View File

@@ -4,7 +4,10 @@ const router = express.Router();
// GET home page // GET home page
router.get('/', (req, res, next) => { router.get('/', (req, res, next) => {
// The ssoHandler middleware has already attached the user to res.locals // 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 // GET logout

View File

@@ -69,6 +69,10 @@
</main> </main>
</div> </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> <script src="/js/sso.js"></script>
</body> </body>
</html> </html>