]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/oauth/oauth-client.ts
Merge branch 'release/3.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / models / oauth / oauth-client.ts
CommitLineData
3fd3ab2d 1import { AllowNull, Column, CreatedAt, DataType, HasMany, Model, Table, UpdatedAt } from 'sequelize-typescript'
16c016e8 2import { AttributesOnly } from '@shared/core-utils'
3fd3ab2d 3import { OAuthTokenModel } from './oauth-token'
e02643f3 4
3fd3ab2d
C
5@Table({
6 tableName: 'oAuthClient',
7 indexes: [
feb4bdfd 8 {
3fd3ab2d
C
9 fields: [ 'clientId' ],
10 unique: true
feb4bdfd
C
11 },
12 {
3fd3ab2d
C
13 fields: [ 'clientId', 'clientSecret' ],
14 unique: true
feb4bdfd 15 }
3fd3ab2d
C
16 ]
17})
16c016e8 18export class OAuthClientModel extends Model<Partial<AttributesOnly<OAuthClientModel>>> {
feb4bdfd 19
3fd3ab2d
C
20 @AllowNull(false)
21 @Column
22 clientId: string
e02643f3 23
3fd3ab2d
C
24 @AllowNull(false)
25 @Column
26 clientSecret: string
e02643f3 27
3acc5084 28 @Column(DataType.ARRAY(DataType.STRING))
3fd3ab2d
C
29 grants: string[]
30
3acc5084 31 @Column(DataType.ARRAY(DataType.STRING))
3fd3ab2d
C
32 redirectUris: string[]
33
34 @CreatedAt
35 createdAt: Date
69b0a27c 36
3fd3ab2d
C
37 @UpdatedAt
38 updatedAt: Date
69b0a27c 39
3fd3ab2d 40 @HasMany(() => OAuthTokenModel, {
e02643f3
C
41 onDelete: 'cascade'
42 })
3fd3ab2d 43 OAuthTokens: OAuthTokenModel[]
e02643f3 44
3fd3ab2d
C
45 static countTotal () {
46 return OAuthClientModel.count()
47 }
69b0a27c 48
3fd3ab2d
C
49 static loadFirstClient () {
50 return OAuthClientModel.findOne()
51 }
69b0a27c 52
3fd3ab2d
C
53 static getByIdAndSecret (clientId: string, clientSecret: string) {
54 const query = {
55 where: {
56 clientId: clientId,
57 clientSecret: clientSecret
58 }
feb4bdfd 59 }
feb4bdfd 60
3fd3ab2d
C
61 return OAuthClientModel.findOne(query)
62 }
69b0a27c 63}