認証の修正 (#7597)

* authenticateのキャッシュを廃止

* 凍結ユーザーがサインイン出来てしまうのを修正

* 凍結ユーザーはストリーミング接続出来ないように

* 他人のアクセストークンはrevoke出来ないように, 正常削除を待機するように

* ユーザー/アクセストークンを無効化したらストリーミングを切断するように

* Revert TODO

* ストリーミングterminateは、ユーザー削除後に行うように

* signinでsuspendは別のエラーにする

* トークン再生成後のストリーミング切断は少し待つように

* サスペンド後のストリーミング切断はローカルユーザーのみに
This commit is contained in:
MeiMei
2021-07-18 19:57:53 +09:00
committed by GitHub
parent 62dede02ea
commit 04e27e160e
8 changed files with 41 additions and 15 deletions

View File

@ -2,11 +2,6 @@ import isNativeToken from './common/is-native-token';
import { User } from '../../models/entities/user';
import { Users, AccessTokens, Apps } from '../../models';
import { AccessToken } from '../../models/entities/access-token';
import { Cache } from '@/misc/cache';
// TODO: TypeORMのカスタムキャッシュプロバイダを使っても良いかも
// ref. https://github.com/typeorm/typeorm/blob/master/docs/caching.md
const cache = new Cache<User>(1000 * 60 * 60);
export class AuthenticationError extends Error {
constructor(message: string) {
@ -21,11 +16,6 @@ export default async (token: string): Promise<[User | null | undefined, App | nu
}
if (isNativeToken(token)) {
const cached = cache.get(token);
if (cached) {
return [cached, null];
}
// Fetch user
const user = await Users
.findOne({ token });
@ -34,11 +24,8 @@ export default async (token: string): Promise<[User | null | undefined, App | nu
throw new AuthenticationError('user not found');
}
cache.set(token, user);
return [user, null];
} else {
// TODO: cache
const accessToken = await AccessTokens.findOne({
where: [{
hash: token.toLowerCase() // app