This repository was archived by the owner on Sep 16, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathApiAuthentication.js
More file actions
160 lines (160 loc) · 4.59 KB
/
Copy pathApiAuthentication.js
File metadata and controls
160 lines (160 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
'use strict'
module.exports = (sequelize, DataTypes) => {
const ApiAuthentication = sequelize.define(
'ApiAuthentication', {
id: {
type: DataTypes.INTEGER(10).UNSIGNED,
primaryKey: true,
allowNull: false,
autoIncrement: true,
comment: 'Unique ID'
},
user_id: {
type: DataTypes.INTEGER(10).UNSIGNED,
comment: 'Unique User ID'
},
approved_whitelist: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: 'localhost',
comment: 'Comma Separated list of Domains'
},
api_key: {
type: DataTypes.STRING(128),
allowNull: false,
unique: 'api_key',
comment: 'UUID based API Key'
},
api_secret: {
type: DataTypes.STRING(128),
allowNull: false,
unique: 'api_secret',
comment: 'UUID based API Security Key'
},
allow_api_get: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true,
comment: 'Whether to Allow API Key User access to HTTP GET Method'
},
allow_api_post: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
comment: 'Whether to Allow API Key User access to HTTP POST Method'
},
allow_api_put: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
comment: 'Whether to Allow API Key User access to HTTP PUT Method'
},
allow_api_delete: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
comment: 'Whether to Allow API Key User access to HTTP DELETE Method'
},
allow_content_management: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
comment: 'Whether to Allow API Key User to Managing Content ( possibly helpful for CMS related APIs )'
},
allow_user_registration: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
comment: 'Whether to Allow API Key User to Create Users'
},
app_name: {
type: DataTypes.STRING(128),
allowNull: false,
comment: 'Marketing Name of App using for our API'
},
app_type: {
type: DataTypes.ENUM,
values: ['web_app', 'mobile_app', 'os_app', 'tv_app', 'custom_app', 'developer'],
allowNull: false,
defaultValue: 'developer',
comment: 'Type of Application using the API'
},
app_purpose: {
type: DataTypes.TEXT,
comment: 'Developers Purpose of App using for our API'
},
app_description: {
type: DataTypes.TEXT,
comment: 'Marketing Description of App using for our API'
},
daily_limit: {
type: DataTypes.INTEGER(10),
allowNull: false,
defaultValue: 2500,
comment: 'Maximum Number of API calls in 24 hours ( 0 = unlimited )'
},
status: {
type: DataTypes.ENUM,
values: ['pending_approval', 'approved', 'rejected', 'developer_terminated', 'deleted'],
allowNull: false,
defaultValue: 'pending_approval',
comment: 'Approval Status of API Key'
},
expire_date: {
type: DataTypes.DATEONLY,
comment: 'Date when the API Key will Expire'
}
}, {
timestamps: true,
paranoid: true,
freezeTableName: true,
singular: 'api_authentication',
plural: 'api_authentications',
tableName: 'api_authentication',
engine: 'InnoDB',
collate: 'utf8_unicode_ci',
charset: 'utf8mb4',
comment: 'Api Authentication Model',
indexes: [{
name: 'idx_allow_api_get',
fields: ['allow_api_get']
},
{
name: 'idx_allow_api_post',
fields: ['allow_api_post']
},
{
name: 'idx_allow_api_put',
fields: ['allow_api_put']
},
{
name: 'idx_allow_api_delete',
fields: ['allow_api_delete']
},
{
name: 'idx_allow_content_management',
fields: ['allow_content_management']
},
{
name: 'idx_allow_user_registration',
fields: ['allow_user_registration']
},
{
name: 'idx_status',
fields: ['status']
},
{
name: 'idx_app_type',
fields: ['app_type']
}
]
}
)
ApiAuthentication.associate = function(models) {
ApiAuthentication.belongsTo(models.User, {
foreignKey: 'user_id',
target: 'id'
})
}
return ApiAuthentication
}