From f43db2f46ee50bacb402a6ef42d768694c2bc9a8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 12 Mar 2021 15:20:46 +0100 Subject: Refactor auth flow Reimplement some node-oauth2-server methods to remove hacky code needed by our external login workflow --- server/models/oauth/oauth-token.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'server/models/oauth/oauth-token.ts') diff --git a/server/models/oauth/oauth-token.ts b/server/models/oauth/oauth-token.ts index 6bc6cf27c..27e643aa7 100644 --- a/server/models/oauth/oauth-token.ts +++ b/server/models/oauth/oauth-token.ts @@ -12,9 +12,10 @@ import { Table, UpdatedAt } from 'sequelize-typescript' +import { TokensCache } from '@server/lib/auth/tokens-cache' +import { MUserAccountId } from '@server/types/models' import { MOAuthTokenUser } from '@server/types/models/oauth/oauth-token' import { logger } from '../../helpers/logger' -import { clearCacheByToken } from '../../lib/oauth-model' import { AccountModel } from '../account/account' import { UserModel } from '../account/user' import { ActorModel } from '../activitypub/actor' @@ -26,9 +27,7 @@ export type OAuthTokenInfo = { client: { id: number } - user: { - id: number - } + user: MUserAccountId token: MOAuthTokenUser } @@ -133,7 +132,7 @@ export class OAuthTokenModel extends Model { @AfterUpdate @AfterDestroy static removeTokenCache (token: OAuthTokenModel) { - return clearCacheByToken(token.accessToken) + return TokensCache.Instance.clearCacheByToken(token.accessToken) } static loadByRefreshToken (refreshToken: string) { @@ -206,6 +205,8 @@ export class OAuthTokenModel extends Model { } static deleteUserToken (userId: number, t?: Transaction) { + TokensCache.Instance.deleteUserToken(userId) + const query = { where: { userId -- cgit v1.2.3