summaryrefslogtreecommitdiff
path: root/src/server/api/authenticate.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-11-13 12:23:49 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-11-13 12:23:49 +0900
commit2795fe457909c687f668d020ef65d52abc3182fb (patch)
tree0a52e4e4d854333496fcc487560c93c3de5d5eb5 /src/server/api/authenticate.ts
parentMerge branch 'develop' (diff)
parent12.96.0 (diff)
downloadmisskey-2795fe457909c687f668d020ef65d52abc3182fb.tar.gz
misskey-2795fe457909c687f668d020ef65d52abc3182fb.tar.bz2
misskey-2795fe457909c687f668d020ef65d52abc3182fb.zip
Merge branch 'develop'
Diffstat (limited to 'src/server/api/authenticate.ts')
-rw-r--r--src/server/api/authenticate.ts62
1 files changed, 0 insertions, 62 deletions
diff --git a/src/server/api/authenticate.ts b/src/server/api/authenticate.ts
deleted file mode 100644
index b8e216edc4..0000000000
--- a/src/server/api/authenticate.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-import isNativeToken from './common/is-native-token';
-import { User } from '@/models/entities/user';
-import { Users, AccessTokens, Apps } from '@/models/index';
-import { AccessToken } from '@/models/entities/access-token';
-
-export class AuthenticationError extends Error {
- constructor(message: string) {
- super(message);
- this.name = 'AuthenticationError';
- }
-}
-
-export default async (token: string): Promise<[User | null | undefined, App | null | undefined]> => {
- if (token == null) {
- return [null, null];
- }
-
- if (isNativeToken(token)) {
- // Fetch user
- const user = await Users
- .findOne({ token });
-
- if (user == null) {
- throw new AuthenticationError('user not found');
- }
-
- return [user, null];
- } else {
- const accessToken = await AccessTokens.findOne({
- where: [{
- hash: token.toLowerCase() // app
- }, {
- token: token // miauth
- }],
- });
-
- if (accessToken == null) {
- throw new AuthenticationError('invalid signature');
- }
-
- AccessTokens.update(accessToken.id, {
- lastUsedAt: new Date(),
- });
-
- const user = await Users
- .findOne({
- id: accessToken.userId // findOne(accessToken.userId) のように書かないのは後方互換性のため
- });
-
- if (accessToken.appId) {
- const app = await Apps
- .findOneOrFail(accessToken.appId);
-
- return [user, {
- id: accessToken.id,
- permission: app.permission
- } as AccessToken];
- } else {
- return [user, accessToken];
- }
- }
-};