aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/oauth-client.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/oauth-client.ts')
-rw-r--r--server/models/oauth-client.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/server/models/oauth-client.ts b/server/models/oauth-client.ts
new file mode 100644
index 000000000..3198a85ef
--- /dev/null
+++ b/server/models/oauth-client.ts
@@ -0,0 +1,60 @@
1module.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
43function countTotal (callback) {
44 return this.count().asCallback(callback)
45}
46
47function loadFirstClient (callback) {
48 return this.findOne().asCallback(callback)
49}
50
51function getByIdAndSecret (clientId, clientSecret) {
52 const query = {
53 where: {
54 clientId: clientId,
55 clientSecret: clientSecret
56 }
57 }
58
59 return this.findOne(query)
60}