From 39a734114b491002f1d66ebb338b28cd3ae529ef Mon Sep 17 00:00:00 2001 From: potados99 Date: Tue, 13 Sep 2022 12:43:51 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=ED=95=99=EC=A0=81=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=EC=8B=9C=20=EC=9D=B8=EC=A6=9D=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=EB=8A=94=20=ED=97=A4=EB=8D=94=EC=97=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.ts | 3 +-- lib/external/inu/StudentAccountValidator.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/config.ts b/config.ts index 0cad492..6dc90a4 100644 --- a/config.ts +++ b/config.ts @@ -142,8 +142,7 @@ export default { }, inuApi: { - accountStatusUrl: (studentId: string, password: string) => - `https://api.inuappcenter.kr/account/status?studentId=${studentId}&password=${password}`, + accountStatusUrl: `https://api.inuappcenter.kr/account/status`, key: getSecret('LOGIN_KEY', '앱센터는 모다?'), }, diff --git a/lib/external/inu/StudentAccountValidator.ts b/lib/external/inu/StudentAccountValidator.ts index 0b433b9..1716028 100644 --- a/lib/external/inu/StudentAccountValidator.ts +++ b/lib/external/inu/StudentAccountValidator.ts @@ -41,9 +41,13 @@ export default class StudentAccountValidator { const studentId = this.studentId; const password = this.encryptPassword(); - const url = config.external.inuApi.accountStatusUrl(studentId, password); - const response = await this.getResponse(url); + const url = config.external.inuApi.accountStatusUrl; + const headers = { + authorization: `Basic ${Buffer.from(`${studentId}:${password}`).toString('base64')}`, + }; + + const response = await this.getResponse(url, headers); switch (response.status) { case 200: @@ -59,9 +63,9 @@ export default class StudentAccountValidator { } } - private async getResponse(url: string) { + private async getResponse(url: string, headers: Record) { try { - return await withTimeout(() => fetch(url), 3000, StudentLoginUnavailable); + return await withTimeout(() => fetch(url, {headers}), 3000, StudentLoginUnavailable); } catch (e) { // 응답조차 받지 못하고 예외가 발생한다? 뭔가 잘못된 일이 생긴 것이니, // 적절한 예외(StudentLoginUnavailable)로 치환하여 줍니다.