summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/auth/session
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-11-12 02:02:25 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-11-12 02:02:25 +0900
commit0e4a111f81cceed275d9bec2695f6e401fb654d8 (patch)
tree40874799472fa07416f17b50a398ac33b7771905 /src/server/api/endpoints/auth/session
parentupdate deps (diff)
downloadsharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.gz
sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.bz2
sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.zip
refactoring
Resolve #7779
Diffstat (limited to 'src/server/api/endpoints/auth/session')
-rw-r--r--src/server/api/endpoints/auth/session/generate.ts70
-rw-r--r--src/server/api/endpoints/auth/session/show.ts58
-rw-r--r--src/server/api/endpoints/auth/session/userkey.ts98
3 files changed, 0 insertions, 226 deletions
diff --git a/src/server/api/endpoints/auth/session/generate.ts b/src/server/api/endpoints/auth/session/generate.ts
deleted file mode 100644
index 859cf52ed3..0000000000
--- a/src/server/api/endpoints/auth/session/generate.ts
+++ /dev/null
@@ -1,70 +0,0 @@
-import { v4 as uuid } from 'uuid';
-import $ from 'cafy';
-import config from '@/config/index';
-import define from '../../../define';
-import { ApiError } from '../../../error';
-import { Apps, AuthSessions } from '@/models/index';
-import { genId } from '@/misc/gen-id';
-
-export const meta = {
- tags: ['auth'],
-
- requireCredential: false as const,
-
- params: {
- appSecret: {
- validator: $.str,
- }
- },
-
- res: {
- type: 'object' as const,
- optional: false as const, nullable: false as const,
- properties: {
- token: {
- type: 'string' as const,
- optional: false as const, nullable: false as const,
- },
- url: {
- type: 'string' as const,
- optional: false as const, nullable: false as const,
- format: 'url',
- },
- }
- },
-
- errors: {
- noSuchApp: {
- message: 'No such app.',
- code: 'NO_SUCH_APP',
- id: '92f93e63-428e-4f2f-a5a4-39e1407fe998'
- }
- }
-};
-
-export default define(meta, async (ps) => {
- // Lookup app
- const app = await Apps.findOne({
- secret: ps.appSecret
- });
-
- if (app == null) {
- throw new ApiError(meta.errors.noSuchApp);
- }
-
- // Generate token
- const token = uuid();
-
- // Create session token document
- const doc = await AuthSessions.save({
- id: genId(),
- createdAt: new Date(),
- appId: app.id,
- token: token
- });
-
- return {
- token: doc.token,
- url: `${config.authUrl}/${doc.token}`
- };
-});
diff --git a/src/server/api/endpoints/auth/session/show.ts b/src/server/api/endpoints/auth/session/show.ts
deleted file mode 100644
index 23f1a56a37..0000000000
--- a/src/server/api/endpoints/auth/session/show.ts
+++ /dev/null
@@ -1,58 +0,0 @@
-import $ from 'cafy';
-import define from '../../../define';
-import { ApiError } from '../../../error';
-import { AuthSessions } from '@/models/index';
-
-export const meta = {
- tags: ['auth'],
-
- requireCredential: false as const,
-
- params: {
- token: {
- validator: $.str,
- }
- },
-
- errors: {
- noSuchSession: {
- message: 'No such session.',
- code: 'NO_SUCH_SESSION',
- id: 'bd72c97d-eba7-4adb-a467-f171b8847250'
- }
- },
-
- res: {
- type: 'object' as const,
- optional: false as const, nullable: false as const,
- properties: {
- id: {
- type: 'string' as const,
- optional: false as const, nullable: false as const,
- format: 'id'
- },
- app: {
- type: 'object' as const,
- optional: false as const, nullable: false as const,
- ref: 'App'
- },
- token: {
- type: 'string' as const,
- optional: false as const, nullable: false as const
- }
- }
- }
-};
-
-export default define(meta, async (ps, user) => {
- // Lookup session
- const session = await AuthSessions.findOne({
- token: ps.token
- });
-
- if (session == null) {
- throw new ApiError(meta.errors.noSuchSession);
- }
-
- return await AuthSessions.pack(session, user);
-});
diff --git a/src/server/api/endpoints/auth/session/userkey.ts b/src/server/api/endpoints/auth/session/userkey.ts
deleted file mode 100644
index 72201cb207..0000000000
--- a/src/server/api/endpoints/auth/session/userkey.ts
+++ /dev/null
@@ -1,98 +0,0 @@
-import $ from 'cafy';
-import define from '../../../define';
-import { ApiError } from '../../../error';
-import { Apps, AuthSessions, AccessTokens, Users } from '@/models/index';
-
-export const meta = {
- tags: ['auth'],
-
- requireCredential: false as const,
-
- params: {
- appSecret: {
- validator: $.str,
- },
-
- token: {
- validator: $.str,
- }
- },
-
- res: {
- type: 'object' as const,
- optional: false as const, nullable: false as const,
- properties: {
- accessToken: {
- type: 'string' as const,
- optional: false as const, nullable: false as const,
- },
-
- user: {
- type: 'object' as const,
- optional: false as const, nullable: false as const,
- ref: 'User',
- },
- }
- },
-
- errors: {
- noSuchApp: {
- message: 'No such app.',
- code: 'NO_SUCH_APP',
- id: 'fcab192a-2c5a-43b7-8ad8-9b7054d8d40d'
- },
-
- noSuchSession: {
- message: 'No such session.',
- code: 'NO_SUCH_SESSION',
- id: '5b5a1503-8bc8-4bd0-8054-dc189e8cdcb3'
- },
-
- pendingSession: {
- message: 'This session is not completed yet.',
- code: 'PENDING_SESSION',
- id: '8c8a4145-02cc-4cca-8e66-29ba60445a8e'
- }
- }
-};
-
-export default define(meta, async (ps) => {
- // Lookup app
- const app = await Apps.findOne({
- secret: ps.appSecret
- });
-
- if (app == null) {
- throw new ApiError(meta.errors.noSuchApp);
- }
-
- // Fetch token
- const session = await AuthSessions.findOne({
- token: ps.token,
- appId: app.id
- });
-
- if (session == null) {
- throw new ApiError(meta.errors.noSuchSession);
- }
-
- if (session.userId == null) {
- throw new ApiError(meta.errors.pendingSession);
- }
-
- // Lookup access token
- const accessToken = await AccessTokens.findOneOrFail({
- appId: app.id,
- userId: session.userId
- });
-
- // Delete session
- AuthSessions.delete(session.id);
-
- return {
- accessToken: accessToken.token,
- user: await Users.pack(session.userId, null, {
- detail: true
- })
- };
-});