diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-20 11:31:48 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-09-20 11:45:59 +0200 |
commit | f201a749929ec8094a7ba6bcab7b196870ca5a5e (patch) | |
tree | 76c0f5f8a90705b5badb83f64ffdc395e468c1a9 /server/models/oauth | |
parent | 91411dba928678c15a5e99d9795ae061909e397d (diff) | |
download | PeerTube-f201a749929ec8094a7ba6bcab7b196870ca5a5e.tar.gz PeerTube-f201a749929ec8094a7ba6bcab7b196870ca5a5e.tar.zst PeerTube-f201a749929ec8094a7ba6bcab7b196870ca5a5e.zip |
Cache user token
Diffstat (limited to 'server/models/oauth')
-rw-r--r-- | server/models/oauth/oauth-token.ts | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/server/models/oauth/oauth-token.ts b/server/models/oauth/oauth-token.ts index 1dd5e0289..ef9592c04 100644 --- a/server/models/oauth/oauth-token.ts +++ b/server/models/oauth/oauth-token.ts | |||
@@ -1,10 +1,23 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { |
2 | AfterDelete, | ||
3 | AfterUpdate, | ||
4 | AllowNull, | ||
5 | BelongsTo, | ||
6 | Column, | ||
7 | CreatedAt, | ||
8 | ForeignKey, | ||
9 | Model, | ||
10 | Scopes, | ||
11 | Table, | ||
12 | UpdatedAt | ||
13 | } from 'sequelize-typescript' | ||
2 | import { logger } from '../../helpers/logger' | 14 | import { logger } from '../../helpers/logger' |
3 | import { UserModel } from '../account/user' | 15 | import { UserModel } from '../account/user' |
4 | import { OAuthClientModel } from './oauth-client' | 16 | import { OAuthClientModel } from './oauth-client' |
5 | import { Transaction } from 'sequelize' | 17 | import { Transaction } from 'sequelize' |
6 | import { AccountModel } from '../account/account' | 18 | import { AccountModel } from '../account/account' |
7 | import { ActorModel } from '../activitypub/actor' | 19 | import { ActorModel } from '../activitypub/actor' |
20 | import { clearCacheByToken } from '../../lib/oauth-model' | ||
8 | 21 | ||
9 | export type OAuthTokenInfo = { | 22 | export type OAuthTokenInfo = { |
10 | refreshToken: string | 23 | refreshToken: string |
@@ -112,6 +125,12 @@ export class OAuthTokenModel extends Model<OAuthTokenModel> { | |||
112 | }) | 125 | }) |
113 | OAuthClients: OAuthClientModel[] | 126 | OAuthClients: OAuthClientModel[] |
114 | 127 | ||
128 | @AfterUpdate | ||
129 | @AfterDelete | ||
130 | static removeTokenCache (token: OAuthTokenModel) { | ||
131 | return clearCacheByToken(token.accessToken) | ||
132 | } | ||
133 | |||
115 | static getByRefreshTokenAndPopulateClient (refreshToken: string) { | 134 | static getByRefreshTokenAndPopulateClient (refreshToken: string) { |
116 | const query = { | 135 | const query = { |
117 | where: { | 136 | where: { |