From b7bb2713bfcc98297b0461bd7ef65de7d7e0cc08 Mon Sep 17 00:00:00 2001 From: Dongwon Choi Date: Mon, 12 Feb 2024 15:31:07 +0000 Subject: [PATCH 1/5] Docs: auth.replace.js --- src/routes/docs/auth.replace.js | 105 ++++++++++++++++++++++++++++++++ src/services/auth.replace.js | 2 +- 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 src/routes/docs/auth.replace.js diff --git a/src/routes/docs/auth.replace.js b/src/routes/docs/auth.replace.js new file mode 100644 index 00000000..da9db161 --- /dev/null +++ b/src/routes/docs/auth.replace.js @@ -0,0 +1,105 @@ +const loginReplacePage = require("../../views/loginReplacePage"); +const tag = "auth"; +const apiPrefix = "/auth(dev)"; + +const authReplaceDocs = {}; +authReplaceDocs[`${apiPrefix}/sparcssso`] = { + get: { + tags: [tag], + summary: "자체 로그인 페이지의 html 소스 반환", + description: `Dev 환경에서만 사용할 수 있는 API입니다.
+ SSO를 사용하지 않기 위해 자체 제작된 replace 페이지로 리다이렉트합니다.`, + responses: { + 200: { + description: "자체 로그인 페이지의 html 소스", + content: { + "text/plain": { + type: "string", + example: loginReplacePage, + }, + }, + }, + }, + }, +}; + +authReplaceDocs[`${apiPrefix}/replace`] = { + post: { + tags: [tag], + summary: "요청받은 정보로 로그인 시도", + description: `Dev 환경에서만 사용할 수 있는 API입니다.
+ DB에 존재하는 아이디라면 로그인 진행 후, 이전 페이지로 리다이렉트 합니다.
+ DB에 존재하지 않는 아이디일 경우, 새로운 사용자를 만들고 로그인 진행 후, 이전 페이지로 리다이렉트 합니다.`, + requestBody: { + description: "로그인을 할 사용자의 아이디", + content: { + "application/json": { + schema: { + type: "object", + properties: { + id: { + type: "string", + }, + }, + }, + }, + }, + }, + responses: { + 302: { + description: + "로그인 성공 후 페이지 URI로, 혹은 로그인 실패 URI로 리다이렉트", + headers: { + Location: { + type: "string", + description: "로그인 성공 후 페이지 URI, 혹은 로그인 실패 URI", + format: "uri", + }, + }, + }, + 400: { + content: { + "text/html": { + example: "Auth/replace : invalid request", + }, + }, + }, + }, + }, +}; + +authReplaceDocs[`${apiPrefix}/logout`] = { + get: { + tags: [tag], + summary: "세션 삭제 및 사용자 로그아웃", + description: `Dev 환경에서만 사용할 수 있는 API입니다.
+ 세션을 삭제하여 사용자를 로그아웃 시킵니다.`, + responses: { + 200: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + ssoLogoutUrl: { + type: "string", + description: "SSO 로그아웃 URL", + format: "uri", + }, + }, + }, + }, + }, + }, + 500: { + content: { + "text/html": { + example: "Auth/logout : internal server error", + }, + }, + }, + }, + }, +}; + +module.exports = authReplaceDocs; diff --git a/src/services/auth.replace.js b/src/services/auth.replace.js index a433e6f6..4730272e 100644 --- a/src/services/auth.replace.js +++ b/src/services/auth.replace.js @@ -32,7 +32,7 @@ const loginReplaceHandler = (req, res) => { const { id } = req.body; const loginAfterState = req.session?.loginAfterState; if (!loginAfterState) - return res.status(400).send("SparcsssoCallbackHandler : invalid request"); + return res.status(400).send("Auth/replace : invalid request"); const { redirectOrigin, redirectPath } = loginAfterState; req.session.loginAfterState = undefined; tryLogin(req, res, createUserData(id), redirectOrigin, redirectPath); From ad0edae2eeb7034604c8491c128cc640d8756f5d Mon Sep 17 00:00:00 2001 From: Dongwon Choi Date: Mon, 12 Feb 2024 15:32:19 +0000 Subject: [PATCH 2/5] Docs: fix auth.js --- src/routes/docs/auth.js | 33 +++++++++++++++++++++++++++++---- src/routes/docs/swaggerDocs.js | 2 ++ src/services/auth.js | 6 +++--- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/routes/docs/auth.js b/src/routes/docs/auth.js index a5d6eae6..eeef25aa 100644 --- a/src/routes/docs/auth.js +++ b/src/routes/docs/auth.js @@ -6,8 +6,7 @@ authDocs[`${apiPrefix}/sparcssso`] = { get: { tags: [tag], summary: "SPARCS SSO 로그인 페이지로 리다이렉트", - description: - "Prod의 경우 SSO 로그인 페이지로, Dev의 경우 replace 페이지로 리다이렉트함.", + description: "SSO 로그인 페이지로 리다이렉트합니다.", parameters: [ { in: "query", @@ -46,7 +45,7 @@ authDocs[`${apiPrefix}/sparcssso/callback`] = { tags: [tag], summary: "SPARCS SSO 로그인 페이지에서 다시 리다이렉트를 처리", description: - "SPARCS SSO 로그인 페이지로부터 프론트로 다시 리다이렉트되었을 때 로그인을 시도함.", + "SPARCS SSO 로그인 페이지로부터 프론트로 다시 리다이렉트되었을 때 로그인을 시도.", parameters: [ { in: "query", @@ -80,7 +79,33 @@ authDocs[`${apiPrefix}/sparcssso/callback`] = { 400: { content: { "text/html": { - example: "SparcsssoCallbackHandler : invalid request", + example: "Auth/sparcssso/callback : invalid request", + }, + }, + }, + }, + }, +}; + +authDocs[`${apiPrefix}/login/replace`] = { + get: { + tags: [tag], + summary: "replace 로그인 시도", + description: + "개발용으로 만들어진 replace 로그인을 시도합니다. Prod 환경일 경우 error를 반환합니다.", + responses: { + 400: { + content: { + "application/json": { + schema: { + type: "object", + properties: { + error: { + type: "string", + example: "Auth/login/replace : Bad Request", + }, + }, + }, }, }, }, diff --git a/src/routes/docs/swaggerDocs.js b/src/routes/docs/swaggerDocs.js index a6dab17a..4df25778 100644 --- a/src/routes/docs/swaggerDocs.js +++ b/src/routes/docs/swaggerDocs.js @@ -4,6 +4,7 @@ const reportsDocs = require("./reports"); const logininfoDocs = require("./logininfo"); const locationsDocs = require("./locations"); const authDocs = require("./auth"); +const authReplaceDocs = require("./auth.replace"); const usersDocs = require("./users"); const roomsDocs = require("./rooms"); const chatsDocs = require("./chats"); @@ -76,6 +77,7 @@ const swaggerDocs = { ...locationsDocs, ...usersDocs, ...authDocs, + ...authReplaceDocs, ...chatsDocs, ...roomsDocs, }, diff --git a/src/services/auth.js b/src/services/auth.js index 83b598de..dab7cd64 100644 --- a/src/services/auth.js +++ b/src/services/auth.js @@ -119,13 +119,13 @@ const sparcsssoCallbackHandler = (req, res) => { const { state: stateForCmp, code } = req.query; if (!loginAfterState) - return res.status(400).send("SparcsssoCallbackHandler : invalid request"); + return res.status(400).send("Auth/sparcssso/callback : invalid request"); const { state, redirectOrigin, redirectPath } = loginAfterState; req.session.loginAfterState = undefined; if (!state || !redirectOrigin || !redirectPath) { - return res.status(400).send("SparcsssoCallbackHandler : invalid request"); + return res.status(400).send("Auth/sparcssso/callback : invalid request"); } if (state !== stateForCmp) { @@ -150,7 +150,7 @@ const sparcsssoCallbackHandler = (req, res) => { const loginReplaceHandler = (req, res) => { res.status(400).json({ - error: "Auths/login/replace : Bad Request", + error: "Auth/login/replace : Bad Request", }); }; From be466b6bca0406de47bfcfa74fc8a65028d027b0 Mon Sep 17 00:00:00 2001 From: Dongwon Choi Date: Mon, 12 Feb 2024 15:32:36 +0000 Subject: [PATCH 3/5] Remove: markdown document files --- src/routes/docs/README.md | 17 ------- src/routes/docs/auth.replace.md | 83 --------------------------------- 2 files changed, 100 deletions(-) delete mode 100755 src/routes/docs/README.md delete mode 100644 src/routes/docs/auth.replace.md diff --git a/src/routes/docs/README.md b/src/routes/docs/README.md deleted file mode 100755 index e8fecb5d..00000000 --- a/src/routes/docs/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# Backend Route documentation - -## Routes - -### [/auth](auth.md) - -### [/auth](auth.replace.md) **(for dev)** - -### [/chats](chats.md) - -### [/rooms](rooms.md) - -### [/static](static.md) - -### [/users](users.md) - -### [/locations](locations.md) diff --git a/src/routes/docs/auth.replace.md b/src/routes/docs/auth.replace.md deleted file mode 100644 index 1bca6957..00000000 --- a/src/routes/docs/auth.replace.md +++ /dev/null @@ -1,83 +0,0 @@ -## `/auth` **(for dev)** - -- 사용자 생성, 로그인, 로그아웃 등 사용자 상태 관리를 지원하는 API. -- SPARCS SSO 대신 자체 로그인 페이지를 사용하는 개발 전용 API. - -### `/sparcssso` **(GET)** - -- 자체 로그인 페이지의 html 소스를 반환. - -#### URL Parameters - -- 없음 - -#### Response - -- 로그인 페이지의 html 소스 - -#### Errors - -- 없음 - -### `/login/replace` **(POST)** - -- 요청받은 정보로 로그인을 시도 - -#### POST request form - -```javascript -{ - id: String, // 로그인을 할 사용자의 id -} -``` - -#### Response - -- DB에 존재하는 id면 로그인 진행 후 프론트엔드의 첫 페이지로 리다이렉트 -- DB에 존재하지 않는 id면 새로운 사용자를 만들고 로그인을 진행한 후 프론트엔드의 첫 페이지로 리다이렉트 - -#### Errors - -- 없음 - -### `/logout` **(GET)** - -- 세션을 삭제하여 사용자를 로그아웃시킴 - -#### URL Parameters - -- 없음 - -#### Response - -```javascript -{ - status: 200, - data: "logged out successfully", -} -``` - -#### Errors - -- 없음 - -### `/getToken` **(GET)** - -- 세션의 로그인 정보를 토큰으로 만들어 반환 - -#### URL Parameters - -- 없음 - -#### Response - -```javascript -{ - status: 200, - data: String, //JSON Web Token -} -``` - -#### Errors - -- 403 "not logged in" From 09e10880818879ca67099a4cd80a5910dad0a7a7 Mon Sep 17 00:00:00 2001 From: Dongwon Choi Date: Mon, 12 Feb 2024 15:35:51 +0000 Subject: [PATCH 4/5] Refactor: add schemas directory --- src/routes/docs/rooms.js | 1 - src/routes/docs/{ => schemas}/reportsSchema.js | 2 +- src/routes/docs/{ => schemas}/roomsSchema.js | 2 +- src/routes/docs/swaggerDocs.js | 4 ++-- src/routes/reports.js | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) rename src/routes/docs/{ => schemas}/reportsSchema.js (93%) rename src/routes/docs/{ => schemas}/roomsSchema.js (96%) diff --git a/src/routes/docs/rooms.js b/src/routes/docs/rooms.js index 3292b127..d4bf8599 100644 --- a/src/routes/docs/rooms.js +++ b/src/routes/docs/rooms.js @@ -1,4 +1,3 @@ -const { roomsSchema } = require("./roomsSchema"); const { objectIdPattern, roomsPattern } = require("./utils"); const tag = "rooms"; diff --git a/src/routes/docs/reportsSchema.js b/src/routes/docs/schemas/reportsSchema.js similarity index 93% rename from src/routes/docs/reportsSchema.js rename to src/routes/docs/schemas/reportsSchema.js index 654e1178..b1ccc1a1 100644 --- a/src/routes/docs/reportsSchema.js +++ b/src/routes/docs/schemas/reportsSchema.js @@ -1,4 +1,4 @@ -const { objectIdPattern } = require("./utils"); +const { objectIdPattern } = require("../utils"); const reportsSchema = { createHandler: { diff --git a/src/routes/docs/roomsSchema.js b/src/routes/docs/schemas/roomsSchema.js similarity index 96% rename from src/routes/docs/roomsSchema.js rename to src/routes/docs/schemas/roomsSchema.js index e256c5dd..38227dcb 100644 --- a/src/routes/docs/roomsSchema.js +++ b/src/routes/docs/schemas/roomsSchema.js @@ -1,4 +1,4 @@ -const { objectIdPattern, roomsPattern } = require("./utils"); +const { objectIdPattern, roomsPattern } = require("../utils"); const participantSchema = { part: { diff --git a/src/routes/docs/swaggerDocs.js b/src/routes/docs/swaggerDocs.js index 4df25778..3f56903b 100644 --- a/src/routes/docs/swaggerDocs.js +++ b/src/routes/docs/swaggerDocs.js @@ -1,5 +1,5 @@ -const reportsSchema = require("./reportsSchema"); -const { participantSchema, roomsSchema } = require("./roomsSchema"); +const reportsSchema = require("./schemas/reportsSchema"); +const { participantSchema, roomsSchema } = require("./schemas/roomsSchema"); const reportsDocs = require("./reports"); const logininfoDocs = require("./logininfo"); const locationsDocs = require("./locations"); diff --git a/src/routes/reports.js b/src/routes/reports.js index 07fcbf51..09f85a8b 100644 --- a/src/routes/reports.js +++ b/src/routes/reports.js @@ -1,5 +1,5 @@ const express = require("express"); -const reportsSchema = require("./docs/reportsSchema"); +const reportsSchema = require("./docs/schemas/reportsSchema"); const { validateBody } = require("../middlewares/ajv"); const router = express.Router(); const reportHandlers = require("../services/reports"); From d0f4a1d7bacef78505eb041bdd8de5785f6389e8 Mon Sep 17 00:00:00 2001 From: Dongwon Choi Date: Thu, 15 Feb 2024 15:19:41 +0000 Subject: [PATCH 5/5] Docs: fix auth.replace.js prefix typo --- src/routes/docs/auth.replace.js | 4 ++-- src/services/auth.replace.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/routes/docs/auth.replace.js b/src/routes/docs/auth.replace.js index da9db161..8246836b 100644 --- a/src/routes/docs/auth.replace.js +++ b/src/routes/docs/auth.replace.js @@ -23,7 +23,7 @@ authReplaceDocs[`${apiPrefix}/sparcssso`] = { }, }; -authReplaceDocs[`${apiPrefix}/replace`] = { +authReplaceDocs[`${apiPrefix}/login/replace`] = { post: { tags: [tag], summary: "요청받은 정보로 로그인 시도", @@ -60,7 +60,7 @@ authReplaceDocs[`${apiPrefix}/replace`] = { 400: { content: { "text/html": { - example: "Auth/replace : invalid request", + example: "Auth/login/replace : invalid request", }, }, }, diff --git a/src/services/auth.replace.js b/src/services/auth.replace.js index 4730272e..4103a7f0 100644 --- a/src/services/auth.replace.js +++ b/src/services/auth.replace.js @@ -32,7 +32,7 @@ const loginReplaceHandler = (req, res) => { const { id } = req.body; const loginAfterState = req.session?.loginAfterState; if (!loginAfterState) - return res.status(400).send("Auth/replace : invalid request"); + return res.status(400).send("Auth/login/replace : invalid request"); const { redirectOrigin, redirectPath } = loginAfterState; req.session.loginAfterState = undefined; tryLogin(req, res, createUserData(id), redirectOrigin, redirectPath);