]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/oauth-client.ts
Update README
[github/Chocobozzz/PeerTube.git] / server / models / oauth-client.ts
1 module.exports = function (sequelize, DataTypes) {
2 const OAuthClient = sequelize.define('OAuthClient',
3 {
4 clientId: {
5 type: DataTypes.STRING,
6 allowNull: false
7 },
8 clientSecret: {
9 type: DataTypes.STRING,
10 allowNull: false
11 },
12 grants: {
13 type: DataTypes.ARRAY(DataTypes.STRING)
14 },
15 redirectUris: {
16 type: DataTypes.ARRAY(DataTypes.STRING)
17 }
18 },
19 {
20 indexes: [
21 {
22 fields: [ 'clientId' ],
23 unique: true
24 },
25 {
26 fields: [ 'clientId', 'clientSecret' ],
27 unique: true
28 }
29 ],
30 classMethods: {
31 countTotal,
32 getByIdAndSecret,
33 loadFirstClient
34 }
35 }
36 )
37
38 return OAuthClient
39 }
40
41 // ---------------------------------------------------------------------------
42
43 function countTotal (callback) {
44 return this.count().asCallback(callback)
45 }
46
47 function loadFirstClient (callback) {
48 return this.findOne().asCallback(callback)
49 }
50
51 function getByIdAndSecret (clientId, clientSecret) {
52 const query = {
53 where: {
54 clientId: clientId,
55 clientSecret: clientSecret
56 }
57 }
58
59 return this.findOne(query)
60 }