Skip to content

Commit

Permalink
Merge pull request #578 from sparcs-kaist/577-logging-login-deny-reason
Browse files Browse the repository at this point in the history
#577 로그인 거부시 거부 사유를 로그에 기록
  • Loading branch information
kmc7468 authored Feb 22, 2025
2 parents 20791ff + 6457b3c commit f2e47ea
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/services/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ const transUserData = (userData) => {
const kaistInfo = userData.kaist_info ? JSON.parse(userData.kaist_info) : {};

// info.ku_std_no: 학번
// info.isEligible: 카이스트 구성원인지 여부. DB에 저장하지 않음.
// info.isEligible: 카이스트 구성원인지 여부
const info = {
id: userData.uid,
sid: userData.sid,
name: getFullUsername(userData.first_name, userData.last_name),
facebook: userData.facebook_id || "",
twitter: userData.twitter_id || "",
kaist: kaistInfo?.ku_std_no || "",
kaistType: kaistInfo?.employeeType || "", // DB에 저장하지 않음
sparcs: userData.sparcs_id || "",
email: kaistInfo?.mail || userData.email,
isEligible: userPattern.allowedEmployeeTypes.test(kaistInfo?.employeeType),
isEligible: userPattern.allowedEmployeeTypes.test(kaistInfo?.employeeType), // DB에 저장하지 않음
};
return info;
};
Expand Down Expand Up @@ -164,6 +165,8 @@ const sparcsssoCallbackHandler = (req, res) => {
}

if (state !== stateForCmp) {
logger.info("Login denied: state mismatch");

const redirectUrl = new URL("/login/fail", redirectOrigin).href;
return res.redirect(redirectUrl);
}
Expand All @@ -175,7 +178,11 @@ const sparcsssoCallbackHandler = (req, res) => {
tryLogin(req, res, userData, redirectOrigin, redirectPath);
} else {
// 카이스트 구성원이 아닌 경우, SSO 로그아웃 이후, 로그인 실패 URI 로 이동합니다
const { sid } = userData;
const { id, sid, kaist, kaistType } = userData;
logger.info(
`Login denied: not a KAIST member (uid: ${id}, sid: ${sid}, kaist: ${kaist}, kaistType: ${kaistType})`
);

const redirectUrl = new URL("/login/fail", redirectOrigin).href;
const ssoLogoutUrl = ssoClient.getLogoutUrl(sid, redirectUrl);
res.redirect(ssoLogoutUrl);
Expand Down

0 comments on commit f2e47ea

Please sign in to comment.