PeerTube/server/models/oauth/oauth-client.ts

64 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-12-12 17:53:50 +01:00
import { AllowNull, Column, CreatedAt, DataType, HasMany, Model, Table, UpdatedAt } from 'sequelize-typescript'
import { AttributesOnly } from '@shared/typescript-utils'
2017-12-12 17:53:50 +01:00
import { OAuthTokenModel } from './oauth-token'
2017-05-22 20:58:25 +02:00
2017-12-12 17:53:50 +01:00
@Table({
tableName: 'oAuthClient',
indexes: [
2016-12-11 21:50:51 +01:00
{
2017-12-12 17:53:50 +01:00
fields: [ 'clientId' ],
unique: true
2016-12-11 21:50:51 +01:00
},
{
2017-12-12 17:53:50 +01:00
fields: [ 'clientId', 'clientSecret' ],
unique: true
2016-12-11 21:50:51 +01:00
}
2017-12-12 17:53:50 +01:00
]
})
2021-05-12 14:09:04 +02:00
export class OAuthClientModel extends Model<Partial<AttributesOnly<OAuthClientModel>>> {
2016-12-11 21:50:51 +01:00
2017-12-12 17:53:50 +01:00
@AllowNull(false)
@Column
clientId: string
2017-05-22 20:58:25 +02:00
2017-12-12 17:53:50 +01:00
@AllowNull(false)
@Column
clientSecret: string
2017-05-22 20:58:25 +02:00
2019-04-23 09:50:57 +02:00
@Column(DataType.ARRAY(DataType.STRING))
2017-12-12 17:53:50 +01:00
grants: string[]
2019-04-23 09:50:57 +02:00
@Column(DataType.ARRAY(DataType.STRING))
2017-12-12 17:53:50 +01:00
redirectUris: string[]
@CreatedAt
createdAt: Date
2017-12-12 17:53:50 +01:00
@UpdatedAt
updatedAt: Date
2017-12-12 17:53:50 +01:00
@HasMany(() => OAuthTokenModel, {
2017-05-22 20:58:25 +02:00
onDelete: 'cascade'
})
2017-12-12 17:53:50 +01:00
OAuthTokens: OAuthTokenModel[]
2017-05-22 20:58:25 +02:00
2017-12-12 17:53:50 +01:00
static countTotal () {
return OAuthClientModel.count()
}
2017-12-12 17:53:50 +01:00
static loadFirstClient () {
return OAuthClientModel.findOne()
}
2017-12-12 17:53:50 +01:00
static getByIdAndSecret (clientId: string, clientSecret: string) {
const query = {
where: {
2022-07-13 11:58:01 +02:00
clientId,
clientSecret
2017-12-12 17:53:50 +01:00
}
2016-12-11 21:50:51 +01:00
}
2017-12-12 17:53:50 +01:00
return OAuthClientModel.findOne(query)
}
}