Skip to content

Commit

Permalink
[feat] Test login api
Browse files Browse the repository at this point in the history
  • Loading branch information
WooHyunKing committed Sep 5, 2023
1 parent 71e32c0 commit f7336c6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 87 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -58,5 +58,6 @@
"@types/react-csv": "^1.1.3",
"@types/react-table": "^7.7.14",
"@types/styled-components": "^5.1.26"
}
},
"proxy": "http://146.56.98.74:3000"
}
88 changes: 25 additions & 63 deletions src/pages/account/login/Login.tsx
Expand Up @@ -8,87 +8,39 @@ import axios from "axios";
const Login = () => {
const [id, setId] = useState("");
const [password, setPassword] = useState("");
const [samlResponse, setSamlResponse] = useState("");
const [account, setAccount] = useRecoilState(accountAtom);
const navigate = useNavigate();
const [studentId, setStudentId] = useState("");

async function loginPost(id: string, password: string) {
const loginPost = async (id: string, password: string, studentId: string) => {
const response = await axios.post(
"/sso/processAuthnResponse.do",
"/login",
{
autoLogin: "Y",
SAMLRequest:
"3A65828FF982B8FF0105D06ED6791B72782655586BFE69341E49E861FDB70B1C0652AD672B8419D0E855F11C1DE485DB0B778FB784B60D31BB212970AF0786B8D693543DB7790BB8C77C6D3EA1D3CDCAF71E19C00251B0540F5F0EB66D41F13E4A7E5666097E5183FFADE84A1898659AB7BC874C63594E5C75DCF47B32E92A6744F31B6536C4DDD532C84635A7405F6F93DB005B8BF320257ECE49AC8CCA34C463BDD8E66990A97C95898931310C6841037538D0607333C41F01FB8880223EE637ED54AD713CEBB163E302386CF48EE151200953A7AA1C5676E5A7ED6A1937F0B0A873E124D1930B812E6649FE9DD9E9FF8C1BFE78EE9B751DE0FFE37D95905D14A92297E301F5BE299E3B019A74747020F0D5C57837A80CA877130F656F786E",
RelayState: null,
returnPage: "/jsp/sso/ip/login_form.jsp",
userAgent: "PC|MACINTEL|CHROME|114",
relogin: "N",
userId: id,
id: id,
password: password,
token: null,
mobileAgentType: null,
userAgentIp: null,
studentNumber: studentId,
},
{
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7",
Referer: "https://sso.ajou.ac.kr/jsp/sso/ip/login_form.jsp",
Origin: "https://sso.ajou.ac.kr",
Host: "sso.ajou.ac.kr",
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
"Content-Type": "application/json",
},
}
);
console.log(response.data);
// console.log(typeof response.data);
// DOMParser를 사용하여 HTML을 파싱
const parser = new DOMParser();
const doc = parser.parseFromString(response.data, "text/html");

const targetElement = doc.querySelector("input[name=SAMLResponse]");
if (targetElement) {
const targetAttribute = targetElement.getAttribute("value");
if (targetAttribute) {
setSamlResponse(targetAttribute);
}
}

loginSuccess();
}

async function loginSuccess() {
const response = await axios.post(
"/auth/ssoLoginSuccess.do",
{
domainName: "exciform.com",
SAMLResponse: samlResponse,
RelayState: null,
returnPage: "https://mportal.ajou.ac.kr",
},
{
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7",
},
withCredentials: true,
}
);
// const response = await fetch("/login",{
// method:"POST",
// headers:{
// 'Content-Type': "application/json"
// },
// })

console.log(response);
}
};

const onSumbit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
console.log(e);
loginPost(id, password);
console.log(id, password, studentId);
loginPost(id, password, studentId);
};

console.log(samlResponse);
console.log(document.cookie);
return (
<LoginContainer>
<TextLogo src={require("../../../imgs/textLogo.png")} />
Expand All @@ -113,6 +65,16 @@ const Login = () => {
onChange={(e) => setPassword(e.target.value)}
/>
</InputBox>
<InputBox>
<InputTitle> 학번</InputTitle>
<Input
type="text"
placeholder=" 학번을 입력하세요"
id="studentId"
value={studentId}
onChange={(e) => setStudentId(e.target.value)}
/>
</InputBox>
<LoginButton>로그인</LoginButton>
</LoginForm>
</LoginContainer>
Expand Down
23 changes: 0 additions & 23 deletions src/setupProxy.js

This file was deleted.

0 comments on commit f7336c6

Please sign in to comment.