1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 10:19:35 +02:00

Refactor auth flow

Reimplement some node-oauth2-server methods to remove hacky code needed by our external
login workflow
This commit is contained in:
Chocobozzz 2021-03-12 15:20:46 +01:00
parent cae2df6bdc
commit f43db2f46e
No known key found for this signature in database
GPG key ID: 583A612D890159BE
24 changed files with 487 additions and 255 deletions

View file

@ -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