Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#135.9 auth.replace API에 swagger 적용 #458

Merged
merged 6 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions src/routes/docs/README.md

This file was deleted.

33 changes: 29 additions & 4 deletions src/routes/docs/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ authDocs[`${apiPrefix}/sparcssso`] = {
get: {
tags: [tag],
summary: "SPARCS SSO 로그인 페이지로 리다이렉트",
description:
"Prod의 경우 SSO 로그인 페이지로, Dev의 경우 replace 페이지로 리다이렉트함.",
description: "SSO 로그인 페이지로 리다이렉트합니다.",
parameters: [
{
in: "query",
Expand Down Expand Up @@ -46,7 +45,7 @@ authDocs[`${apiPrefix}/sparcssso/callback`] = {
tags: [tag],
summary: "SPARCS SSO 로그인 페이지에서 다시 리다이렉트를 처리",
description:
"SPARCS SSO 로그인 페이지로부터 프론트로 다시 리다이렉트되었을 때 로그인을 시도함.",
"SPARCS SSO 로그인 페이지로부터 프론트로 다시 리다이렉트되었을 때 로그인을 시도.",
parameters: [
{
in: "query",
Expand Down Expand Up @@ -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",
},
},
},
},
},
},
Expand Down
105 changes: 105 additions & 0 deletions src/routes/docs/auth.replace.js
Original file line number Diff line number Diff line change
@@ -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: `<b>Dev 환경에서만 사용할 수 있는 API입니다.</b><br/>
SSO를 사용하지 않기 위해 자체 제작된 replace 페이지로 리다이렉트합니다.`,
responses: {
200: {
description: "자체 로그인 페이지의 html 소스",
content: {
"text/plain": {
type: "string",
example: loginReplacePage,
},
},
},
},
},
};

authReplaceDocs[`${apiPrefix}/login/replace`] = {
post: {
tags: [tag],
summary: "요청받은 정보로 로그인 시도",
description: `<b>Dev 환경에서만 사용할 수 있는 API입니다.</b><br/>
DB에 존재하는 아이디라면 로그인 진행 후, 이전 페이지로 리다이렉트 합니다.<br/>
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/login/replace : invalid request",
},
},
},
},
},
};

authReplaceDocs[`${apiPrefix}/logout`] = {
get: {
tags: [tag],
summary: "세션 삭제 및 사용자 로그아웃",
description: `<b>Dev 환경에서만 사용할 수 있는 API입니다.</b><br/>
세션을 삭제하여 사용자를 로그아웃 시킵니다.`,
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;
83 changes: 0 additions & 83 deletions src/routes/docs/auth.replace.md

This file was deleted.

1 change: 0 additions & 1 deletion src/routes/docs/rooms.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { roomsSchema } = require("./roomsSchema");
const { objectIdPattern, roomsPattern } = require("./utils");

const tag = "rooms";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { objectIdPattern } = require("./utils");
const { objectIdPattern } = require("../utils");

const reportsSchema = {
createHandler: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { objectIdPattern, roomsPattern } = require("./utils");
const { objectIdPattern, roomsPattern } = require("../utils");

const participantSchema = {
part: {
Expand Down
6 changes: 4 additions & 2 deletions src/routes/docs/swaggerDocs.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
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");
const authDocs = require("./auth");
const authReplaceDocs = require("./auth.replace");
const usersDocs = require("./users");
const roomsDocs = require("./rooms");
const chatsDocs = require("./chats");
Expand Down Expand Up @@ -76,6 +77,7 @@ const swaggerDocs = {
...locationsDocs,
...usersDocs,
...authDocs,
...authReplaceDocs,
...chatsDocs,
...roomsDocs,
},
Expand Down
2 changes: 1 addition & 1 deletion src/routes/reports.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
6 changes: 3 additions & 3 deletions src/services/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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",
});
};

Expand Down
2 changes: 1 addition & 1 deletion src/services/auth.replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/login/replace : invalid request");
const { redirectOrigin, redirectPath } = loginAfterState;
req.session.loginAfterState = undefined;
tryLogin(req, res, createUserData(id), redirectOrigin, redirectPath);
Expand Down
Loading