PeerTube/server/models/oauth-client.js

63 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-12-28 08:49:23 -06:00
'use strict'
2016-12-11 14:50:51 -06:00
module.exports = function (sequelize, DataTypes) {
const OAuthClient = sequelize.define('OAuthClient',
{
clientId: {
2016-12-28 08:49:23 -06:00
type: DataTypes.STRING,
allowNull: false
2016-12-11 14:50:51 -06:00
},
clientSecret: {
2016-12-28 08:49:23 -06:00
type: DataTypes.STRING,
allowNull: false
2016-12-11 14:50:51 -06:00
},
grants: {
type: DataTypes.ARRAY(DataTypes.STRING)
},
redirectUris: {
type: DataTypes.ARRAY(DataTypes.STRING)
}
},
{
2016-12-29 02:33:28 -06:00
indexes: [
{
fields: [ 'clientId' ],
unique: true
},
{
fields: [ 'clientId', 'clientSecret' ],
unique: true
}
],
2016-12-11 14:50:51 -06:00
classMethods: {
countTotal,
2016-12-11 14:50:51 -06:00
getByIdAndSecret,
loadFirstClient
}
}
)
return OAuthClient
}
// ---------------------------------------------------------------------------
function countTotal (callback) {
return this.count().asCallback(callback)
}
function loadFirstClient (callback) {
2016-12-11 14:50:51 -06:00
return this.findOne().asCallback(callback)
}
2016-12-11 14:50:51 -06:00
function getByIdAndSecret (clientId, clientSecret) {
const query = {
where: {
clientId: clientId,
clientSecret: clientSecret
}
}
return this.findOne(query)
}