2024-02-22 04:12:04 -05:00
|
|
|
import { AllowNull, Column, CreatedAt, DataType, HasMany, Table, UpdatedAt } from 'sequelize-typescript'
|
2023-07-31 08:34:36 -04:00
|
|
|
import { OAuthTokenModel } from './oauth-token.js'
|
2024-02-22 04:12:04 -05:00
|
|
|
import { SequelizeModel } from '../shared/index.js'
|
2017-05-22 14:58:25 -04:00
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
@Table({
|
|
|
|
tableName: 'oAuthClient',
|
|
|
|
indexes: [
|
2016-12-11 15:50:51 -05:00
|
|
|
{
|
2017-12-12 11:53:50 -05:00
|
|
|
fields: [ 'clientId' ],
|
|
|
|
unique: true
|
2016-12-11 15:50:51 -05:00
|
|
|
},
|
|
|
|
{
|
2017-12-12 11:53:50 -05:00
|
|
|
fields: [ 'clientId', 'clientSecret' ],
|
|
|
|
unique: true
|
2016-12-11 15:50:51 -05:00
|
|
|
}
|
2017-12-12 11:53:50 -05:00
|
|
|
]
|
|
|
|
})
|
2024-02-22 04:12:04 -05:00
|
|
|
export class OAuthClientModel extends SequelizeModel<OAuthClientModel> {
|
2016-12-11 15:50:51 -05:00
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
@AllowNull(false)
|
|
|
|
@Column
|
|
|
|
clientId: string
|
2017-05-22 14:58:25 -04:00
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
@AllowNull(false)
|
|
|
|
@Column
|
|
|
|
clientSecret: string
|
2017-05-22 14:58:25 -04:00
|
|
|
|
2019-04-23 03:50:57 -04:00
|
|
|
@Column(DataType.ARRAY(DataType.STRING))
|
2017-12-12 11:53:50 -05:00
|
|
|
grants: string[]
|
|
|
|
|
2019-04-23 03:50:57 -04:00
|
|
|
@Column(DataType.ARRAY(DataType.STRING))
|
2017-12-12 11:53:50 -05:00
|
|
|
redirectUris: string[]
|
|
|
|
|
|
|
|
@CreatedAt
|
|
|
|
createdAt: Date
|
2016-07-01 10:03:53 -04:00
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
@UpdatedAt
|
|
|
|
updatedAt: Date
|
2016-07-01 10:03:53 -04:00
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
@HasMany(() => OAuthTokenModel, {
|
2017-05-22 14:58:25 -04:00
|
|
|
onDelete: 'cascade'
|
|
|
|
})
|
2023-07-31 08:34:36 -04:00
|
|
|
OAuthTokens: Awaited<OAuthTokenModel>[]
|
2017-05-22 14:58:25 -04:00
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
static countTotal () {
|
|
|
|
return OAuthClientModel.count()
|
|
|
|
}
|
2016-07-01 10:03:53 -04:00
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
static loadFirstClient () {
|
|
|
|
return OAuthClientModel.findOne()
|
|
|
|
}
|
2016-07-01 10:03:53 -04:00
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
static getByIdAndSecret (clientId: string, clientSecret: string) {
|
|
|
|
const query = {
|
|
|
|
where: {
|
2022-07-13 05:58:01 -04:00
|
|
|
clientId,
|
|
|
|
clientSecret
|
2017-12-12 11:53:50 -05:00
|
|
|
}
|
2016-12-11 15:50:51 -05:00
|
|
|
}
|
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
return OAuthClientModel.findOne(query)
|
|
|
|
}
|
2016-07-01 10:03:53 -04:00
|
|
|
}
|