Skip to content

Commit

Permalink
refactor: 학적 확인시 인증 정보는 헤더에
Browse files Browse the repository at this point in the history
  • Loading branch information
potados99 committed Sep 13, 2022
1 parent 638165f commit 39a7341
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 1 addition & 2 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', '앱센터는 모다?'),
},

Expand Down
12 changes: 8 additions & 4 deletions lib/external/inu/StudentAccountValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -59,9 +63,9 @@ export default class StudentAccountValidator {
}
}

private async getResponse(url: string) {
private async getResponse(url: string, headers: Record<string, any>) {
try {
return await withTimeout(() => fetch(url), 3000, StudentLoginUnavailable);
return await withTimeout(() => fetch(url, {headers}), 3000, StudentLoginUnavailable);
} catch (e) {
// 응답조차 받지 못하고 예외가 발생한다? 뭔가 잘못된 일이 생긴 것이니,
// 적절한 예외(StudentLoginUnavailable)로 치환하여 줍니다.
Expand Down

0 comments on commit 39a7341

Please sign in to comment.