beech-api 3.7.23 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +490 -168
- package/index.js +2 -2
- package/package.json +8 -1
- package/packages/cli/beech +2 -2
- package/packages/cli/bin/beech-app.js +10 -8
- package/packages/cli/bin/beech-service.js +1 -1
- package/packages/cli/core/auth/Credentials.js +139 -89
- package/packages/cli/core/auth/Passport.js +264 -164
- package/packages/cli/core/auth/_Request.js +1 -1
- package/packages/cli/core/configure/app.config-basic.js +2 -2
- package/packages/cli/core/configure/app.config-sequelize.js +2 -2
- package/packages/cli/core/configure/beech.config.js +1 -0
- package/packages/cli/core/configure/passport.config.js +33 -13
- package/packages/cli/core/databases/sequelize.js +3 -0
- package/packages/cli/core/databases/test.js +5 -3
- package/packages/cli/core/generator/_endpoints +5 -9
- package/packages/cli/core/generator/_endpoints_basic +11 -8
- package/packages/cli/core/generator/_help +1 -1
- package/packages/cli/core/generator/_models +5 -4
- package/packages/cli/core/generator/_models_basic +2 -2
- package/packages/cli/core/generator/_package +5 -1
- package/packages/cli/core/generator/{_add-on → _scheduler} +1 -1
- package/packages/cli/core/generator/_spec +15 -10
- package/packages/cli/core/generator/index.js +19 -44
- package/packages/cli/core/helpers/2fa.js +85 -0
- package/packages/cli/core/helpers/math.js +55 -7
- package/packages/cli/core/helpers/poolEntity.js +29 -1
- package/packages/cli/core/index.js +65 -34
- package/packages/cli/core/middleware/express/duplicateRequest.js +12 -0
- package/packages/cli/core/middleware/express/jwtCheckAllow.js +68 -0
- package/packages/cli/core/middleware/express/rateLimit.js +17 -0
- package/packages/cli/core/middleware/express/slowDown.js +2 -0
- package/packages/cli/core/middleware/index.js +6 -0
- package/packages/cli/core/middleware/origin/guard/advance.js +74 -0
- package/packages/cli/core/{origin → middleware/origin}/whitelist/cors.js +15 -12
- package/packages/cli/core/services/http.express.js +116 -72
- package/packages/lib/index.js +3 -1
- package/packages/lib/src/endpoint.js +523 -89
- package/packages/lib/src/guard.js +61 -0
- package/packages/lib/src/schema.js +57 -26
- package/packages/lib/src/specificExpress.js +7 -0
- package/packages/lib/src/user.js +94 -18
- package/packages/cli/core/origin/index.js +0 -2
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
const appRoot = require("app-root-path");
|
|
2
1
|
const fs = require("fs");
|
|
3
|
-
const passport_config_file = appRoot + "
|
|
2
|
+
const passport_config_file = appRoot + "/passport.config.js";
|
|
4
3
|
const md5 = require("md5");
|
|
5
4
|
const secret = require("../../../lib/src/salt").salt;
|
|
6
|
-
const { findPassportPk } = require("../helpers/poolEntity");
|
|
5
|
+
const { findPassportPk, checkAuthFields } = require("../helpers/poolEntity");
|
|
7
6
|
const { Rand } = require("../helpers/math");
|
|
8
7
|
const { QueryTypes } = require("sequelize");
|
|
9
8
|
|
|
@@ -19,10 +18,16 @@ module.exports = {
|
|
|
19
18
|
*
|
|
20
19
|
*/
|
|
21
20
|
if (fs.existsSync(passport_config_file)) {
|
|
22
|
-
const
|
|
21
|
+
const { byPassCredentials, credentialsGuard } = require("./Credentials");
|
|
23
22
|
passport_config = require(passport_config_file);
|
|
24
|
-
if
|
|
25
|
-
|
|
23
|
+
// Check if the JWT is allow
|
|
24
|
+
if (passport_config.jwt_allow === true) {
|
|
25
|
+
// Check if the APP_KEY is allow
|
|
26
|
+
if(passport_config.app_key_allow) {
|
|
27
|
+
global.Credentials = (_options = {}, _res, _next) => [credentialsGuard, byPassCredentials(_options, _res, _next)];
|
|
28
|
+
} else {
|
|
29
|
+
global.Credentials = (_options = {}, _res, _next) => [byPassCredentials(_options, _res, _next)];
|
|
30
|
+
}
|
|
26
31
|
// loop check db connect is true
|
|
27
32
|
fs.readFile("./app.config.js", "utf-8", (err, data) => {
|
|
28
33
|
if(err) {
|
|
@@ -46,14 +51,17 @@ module.exports = {
|
|
|
46
51
|
});
|
|
47
52
|
}
|
|
48
53
|
});
|
|
54
|
+
} else if (passport_config.app_key_allow === true) {
|
|
55
|
+
global.Credentials = (_options = {}, _res, _next) => [credentialsGuard];
|
|
56
|
+
resolve([true, false, null]);
|
|
49
57
|
} else {
|
|
50
|
-
global.Credentials = [];
|
|
58
|
+
global.Credentials = (_options = {}, _res, _next) => [];
|
|
51
59
|
resolve([true, false, null]);
|
|
52
60
|
}
|
|
53
61
|
} else {
|
|
54
|
-
global.Credentials = [];
|
|
62
|
+
global.Credentials = (_options = {}, _res, _next) => [];
|
|
55
63
|
//const Requests = require("./_Request");
|
|
56
|
-
//global.Credentials = Requests.requests; ----> // [Closed] TODO check passport.config file if not exists show error when file src/ using the JWT (maybe for show JWT is ON/OFF)
|
|
64
|
+
//global.Credentials = (_options = {}, _res, _next) => [Requests.requests]; ----> // [Closed] TODO check passport.config file if not exists show error when file src/ using the JWT (maybe for show JWT is ON/OFF)
|
|
57
65
|
resolve([false, null, null]);
|
|
58
66
|
}
|
|
59
67
|
});
|
|
@@ -72,72 +80,30 @@ module.exports = {
|
|
|
72
80
|
var passportPasswordField = passport_config.model.password_field || "password";
|
|
73
81
|
var passportTable = passport_config.model.table || "users";
|
|
74
82
|
var pool = eval("sql." + passport_config.model.name);
|
|
75
|
-
|
|
76
|
-
findPassportPk(pool_base, pool, passportTable, passport_config.model.fields, (err, passportFields) => {
|
|
83
|
+
checkAuthFields(pool_base, pool, passportTable, passport_config.model.fields, (err, msg) => {
|
|
77
84
|
if(err) {
|
|
78
|
-
|
|
85
|
+
console.error("\n[101m Error [0m", err);
|
|
86
|
+
return;
|
|
79
87
|
} else {
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}, async (username, password, done) => {
|
|
85
|
-
if (pool) {
|
|
86
|
-
if (pool_base == "basic") {
|
|
87
|
-
// pool base is MySQL
|
|
88
|
-
pool.query("SELECT " + passportFields + " FROM ?? WHERE ?? = ? AND ?? = ?", [
|
|
89
|
-
passportTable,
|
|
90
|
-
passportUsernameField,
|
|
91
|
-
username,
|
|
92
|
-
passportPasswordField,
|
|
93
|
-
md5(password + secret)
|
|
94
|
-
], (err, result) => {
|
|
95
|
-
if (err) {
|
|
96
|
-
return done(err, null);
|
|
97
|
-
} else {
|
|
98
|
-
return done(null, JSON.parse(JSON.stringify(result[ 0 ] || null)));
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
} else if (pool_base == "sequelize") {
|
|
102
|
-
// pool base is Sequelize
|
|
103
|
-
try {
|
|
104
|
-
let result = await pool.query("SELECT " + passportFields + " FROM " + passportTable + " WHERE " + passportUsernameField + " = :username AND " + passportPasswordField + " = :password", {
|
|
105
|
-
replacements: {
|
|
106
|
-
fields: passportFields,
|
|
107
|
-
username: username,
|
|
108
|
-
password: md5(password + secret)
|
|
109
|
-
},
|
|
110
|
-
type: QueryTypes.SELECT
|
|
111
|
-
});
|
|
112
|
-
return done(null, JSON.parse(JSON.stringify(result[ 0 ] || null)));
|
|
113
|
-
} catch (error) {
|
|
114
|
-
return done(error, null);
|
|
115
|
-
}
|
|
116
|
-
} else {
|
|
117
|
-
return done({ error: "The Base pool error. UNKNOWN pool_base = '"+ pool_base +"'" }, null);
|
|
118
|
-
}
|
|
88
|
+
// find passport primary key
|
|
89
|
+
findPassportPk(pool_base, pool, passportTable, passport_config.model.fields, (err, passportFields) => {
|
|
90
|
+
if(err) {
|
|
91
|
+
resolve([err, true, true, true]);
|
|
119
92
|
} else {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
secretOrKey: passport_config.secret
|
|
128
|
-
}, async (jwtPayload, done) => {
|
|
129
|
-
let pool = eval("sql." + passport_config.model.name);
|
|
130
|
-
if (pool) {
|
|
131
|
-
if (pool_base == "basic") {
|
|
132
|
-
pool.query("SHOW KEYS FROM " + passportTable + " WHERE Key_name = 'PRIMARY'", (err, pk) => {
|
|
133
|
-
if(err) {
|
|
134
|
-
return done(err, null);
|
|
135
|
-
} else {
|
|
136
|
-
let fieldPk = pk[0].Column_name;
|
|
93
|
+
// Passport initial with token (encoder)
|
|
94
|
+
passport.use(new LocalStrategy({
|
|
95
|
+
usernameField: passportUsernameField,
|
|
96
|
+
passwordField: passportPasswordField
|
|
97
|
+
}, async (username, password, done) => {
|
|
98
|
+
if (pool) {
|
|
99
|
+
if (pool_base == "basic") {
|
|
137
100
|
// pool base is MySQL
|
|
138
|
-
pool.query("SELECT " + passportFields + " FROM ?? WHERE
|
|
101
|
+
pool.query("SELECT " + passportFields + " FROM ?? WHERE ?? = ? AND ?? = ?", [
|
|
139
102
|
passportTable,
|
|
140
|
-
|
|
103
|
+
passportUsernameField,
|
|
104
|
+
username,
|
|
105
|
+
passportPasswordField,
|
|
106
|
+
md5(password + secret)
|
|
141
107
|
], (err, result) => {
|
|
142
108
|
if (err) {
|
|
143
109
|
return done(err, null);
|
|
@@ -145,99 +111,170 @@ module.exports = {
|
|
|
145
111
|
return done(null, JSON.parse(JSON.stringify(result[ 0 ] || null)));
|
|
146
112
|
}
|
|
147
113
|
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
type: QueryTypes.SELECT,
|
|
160
|
-
}).then((result) => {
|
|
114
|
+
} else if (pool_base == "sequelize") {
|
|
115
|
+
// pool base is Sequelize
|
|
116
|
+
try {
|
|
117
|
+
let result = await pool.query("SELECT " + passportFields + " FROM " + passportTable + " WHERE " + passportUsernameField + " = :username AND " + passportPasswordField + " = :password", {
|
|
118
|
+
replacements: {
|
|
119
|
+
fields: passportFields,
|
|
120
|
+
username: username,
|
|
121
|
+
password: md5(password + secret)
|
|
122
|
+
},
|
|
123
|
+
type: QueryTypes.SELECT
|
|
124
|
+
});
|
|
161
125
|
return done(null, JSON.parse(JSON.stringify(result[ 0 ] || null)));
|
|
162
|
-
}
|
|
163
|
-
return done(
|
|
126
|
+
} catch (error) {
|
|
127
|
+
return done(error, null);
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
return done({ error: "The Base pool error. UNKNOWN pool_base = '"+ pool_base +"'" }, null);
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
return done(null, null, true);
|
|
134
|
+
}
|
|
135
|
+
}));
|
|
136
|
+
|
|
137
|
+
// Passport jwt payload (decoder)
|
|
138
|
+
passport.use(new JWTStrategy({
|
|
139
|
+
jwtFromRequest: ExtractJWT.fromAuthHeaderAsBearerToken(),
|
|
140
|
+
secretOrKey: passport_config.secret
|
|
141
|
+
}, async (jwtPayload, done) => {
|
|
142
|
+
let pool = eval("sql." + passport_config.model.name);
|
|
143
|
+
if (pool) {
|
|
144
|
+
if (pool_base == "basic") {
|
|
145
|
+
pool.query("SHOW KEYS FROM " + passportTable + " WHERE Key_name = 'PRIMARY'", (err, pk) => {
|
|
146
|
+
if(err) {
|
|
147
|
+
return done(err, null);
|
|
148
|
+
} else {
|
|
149
|
+
let fieldPk = pk[0].Column_name;
|
|
150
|
+
// pool base is MySQL
|
|
151
|
+
pool.query("SELECT " + passportFields + " FROM ?? WHERE " + fieldPk + " = ?", [
|
|
152
|
+
passportTable,
|
|
153
|
+
jwtPayload[fieldPk]
|
|
154
|
+
], (err, result) => {
|
|
155
|
+
if (err) {
|
|
156
|
+
return done(err, null);
|
|
157
|
+
} else {
|
|
158
|
+
return done(null, JSON.parse(JSON.stringify(result[ 0 ] || null)));
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
164
162
|
});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
163
|
+
} else if (pool_base == "sequelize") {
|
|
164
|
+
// pool base is Sequelize
|
|
165
|
+
try {
|
|
166
|
+
pool.query("SHOW KEYS FROM " + passportTable + " WHERE Key_name = 'PRIMARY'", { type: QueryTypes.SELECT }).then((pk) => {
|
|
167
|
+
let fieldPk = pk[0].Column_name;
|
|
168
|
+
pool.query("SELECT " + passportFields + " FROM " + passportTable + " WHERE " + fieldPk + " = :pk", {
|
|
169
|
+
replacements: {
|
|
170
|
+
pk: + jwtPayload[fieldPk]
|
|
171
|
+
},
|
|
172
|
+
type: QueryTypes.SELECT,
|
|
173
|
+
}).then((result) => {
|
|
174
|
+
return done(null, JSON.parse(JSON.stringify(result[ 0 ] || null)));
|
|
175
|
+
}).catch((error) => {
|
|
176
|
+
if(pool.options.logging) {
|
|
177
|
+
return done(error, null);
|
|
178
|
+
} else {
|
|
179
|
+
if(error.sql) {
|
|
180
|
+
delete error.sql;
|
|
181
|
+
if(error.errors) {
|
|
182
|
+
delete error.errors;
|
|
183
|
+
}
|
|
184
|
+
if(error.parent) {
|
|
185
|
+
delete error.parent;
|
|
186
|
+
}
|
|
187
|
+
if(error.original) {
|
|
188
|
+
delete error.original.sql;
|
|
189
|
+
}
|
|
190
|
+
if(error.parameters) {
|
|
191
|
+
delete error.parameters;
|
|
192
|
+
}
|
|
193
|
+
return done(error, null);
|
|
194
|
+
} else {
|
|
195
|
+
return done(String(error), null);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}).catch((err) => {
|
|
200
|
+
return done(err, null);
|
|
201
|
+
});
|
|
202
|
+
} catch (error) {
|
|
203
|
+
return done(error, null);
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
return done({ error: "The Base pool error. UNKNOWN pool_base = '"+ pool_base +"'" }, null);
|
|
207
|
+
}
|
|
208
|
+
} else {
|
|
209
|
+
return done(null, null, true);
|
|
170
210
|
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
resolve([null, true, true, true]);
|
|
239
|
-
} // end if check err findPassportPk
|
|
240
|
-
}); // end findPassportPk
|
|
211
|
+
}));
|
|
212
|
+
|
|
213
|
+
// Declare head authentication enpoint for all strategy
|
|
214
|
+
let auth_endpoint = (passport_config.auth_endpoint) ? (passport_config.auth_endpoint[ 0 ] === "/" ? passport_config.auth_endpoint : "/" + passport_config.auth_endpoint) : "/authentication";
|
|
215
|
+
auth_endpoint = _publicPath_ + auth_endpoint.substr(1);
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Passport Google Strategy
|
|
219
|
+
*
|
|
220
|
+
*/
|
|
221
|
+
let google_callbackURL = (passport_config.strategy.google.callbackURL) ? (passport_config.strategy.google.callbackURL[ 0 ] === "/" ? passport_config.strategy.google.callbackURL : "/" + passport_config.strategy.google.callbackURL) : "/google/callback";
|
|
222
|
+
passport.use(new GoogleStrategy({
|
|
223
|
+
clientID: passport_config.strategy.google.client_id,
|
|
224
|
+
clientSecret: passport_config.strategy.google.client_secret,
|
|
225
|
+
callbackURL: auth_endpoint + google_callbackURL
|
|
226
|
+
}, (accessToken, refreshToken, profile, done) => {
|
|
227
|
+
// find google user
|
|
228
|
+
let googleIdField = (passport_config.strategy.google.local_profile_fields.google_id) ? passport_config.strategy.google.local_profile_fields.google_id : "google_id";
|
|
229
|
+
this.findOrCreate(passport_config, "google", passportFields, passportTable, accessToken, refreshToken, profile, googleIdField, (err, res, dbFailed) => {
|
|
230
|
+
if (err) {
|
|
231
|
+
return done(err);
|
|
232
|
+
} else {
|
|
233
|
+
return done(err, res, dbFailed);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}));
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Passport Facebook Strategy
|
|
240
|
+
*
|
|
241
|
+
*/
|
|
242
|
+
let facebook_callbackURL = (passport_config.strategy.facebook.callbackURL) ? (passport_config.strategy.facebook.callbackURL[ 0 ] === "/" ? passport_config.strategy.facebook.callbackURL : "/" + passport_config.strategy.facebook.callbackURL) : "/facebook/callback";
|
|
243
|
+
// merge fields permisions
|
|
244
|
+
let allow_permisions_fields = [ ...new Set([ ...[ 'id', 'displayName', 'name', 'photos', 'email', 'location' ], ...(passport_config.strategy.facebook.profileFieldsAllow || []) ]) ];
|
|
245
|
+
passport.use(new FacebookStrategy({
|
|
246
|
+
clientID: passport_config.strategy.facebook.app_id,
|
|
247
|
+
clientSecret: passport_config.strategy.facebook.app_secret,
|
|
248
|
+
callbackURL: auth_endpoint + facebook_callbackURL,
|
|
249
|
+
profileFields: allow_permisions_fields
|
|
250
|
+
}, (accessToken, refreshToken, profile, done) => {
|
|
251
|
+
// Check if the email permission is granted
|
|
252
|
+
/**
|
|
253
|
+
* Update : Permissions Reference for Meta Technologies APIs.
|
|
254
|
+
* Starting on or after October 27, 2023, if your app requests permission to use an endpoint to access an app user’s data
|
|
255
|
+
* Learn more : https://developers.facebook.com/docs/permissions
|
|
256
|
+
*
|
|
257
|
+
* From now! Disabled check if email permission granted
|
|
258
|
+
*/
|
|
259
|
+
//if (!profile.emails || profile.emails.length === 0) {
|
|
260
|
+
// return done(new Error('Email permission not granted.'));
|
|
261
|
+
//}
|
|
262
|
+
// find facebook user
|
|
263
|
+
let faecbookIdField = (passport_config.strategy.facebook.local_profile_fields.facebook_id) ? passport_config.strategy.facebook.local_profile_fields.facebook_id : "facebook_id";
|
|
264
|
+
this.findOrCreate(passport_config, "facebook", passportFields, passportTable, accessToken, refreshToken, profile, faecbookIdField, (err, res, dbFailed) => {
|
|
265
|
+
if (err) {
|
|
266
|
+
return done(err);
|
|
267
|
+
} else {
|
|
268
|
+
return done(err, res, dbFailed);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}));
|
|
272
|
+
// Everything is Perfectly
|
|
273
|
+
resolve([null, true, true, true]);
|
|
274
|
+
} // end if check err findPassportPk
|
|
275
|
+
}); // end findPassportPk
|
|
276
|
+
} // end checkAuthFields
|
|
277
|
+
});
|
|
241
278
|
} else if(final[0][0] && final[0][1] && final[0][2] === false) {
|
|
242
279
|
// Database connection mapped is Closed.
|
|
243
280
|
resolve([`Database connection name \`${passport_config.model.name}\` is CLOSED. Checking ON/OFF inside app.conifg.js file.`, true, true, false]);
|
|
@@ -264,7 +301,7 @@ module.exports = {
|
|
|
264
301
|
if (pool) {
|
|
265
302
|
this.query_one_where(pool, "SELECT " + passportFields + " FROM " + passportTable, idField, profile.id, async (err, result) => {
|
|
266
303
|
if (err) {
|
|
267
|
-
cb(err);
|
|
304
|
+
cb(err, null);
|
|
268
305
|
} else {
|
|
269
306
|
// declare data response
|
|
270
307
|
let data = {};
|
|
@@ -344,7 +381,28 @@ module.exports = {
|
|
|
344
381
|
data.google = profile;
|
|
345
382
|
cb(err, data);
|
|
346
383
|
} catch (error) {
|
|
347
|
-
|
|
384
|
+
if(pool.options.logging) {
|
|
385
|
+
return cb(error, null);
|
|
386
|
+
} else {
|
|
387
|
+
if(error.sql) {
|
|
388
|
+
delete error.sql;
|
|
389
|
+
if(error.errors) {
|
|
390
|
+
delete error.errors;
|
|
391
|
+
}
|
|
392
|
+
if(error.parent) {
|
|
393
|
+
delete error.parent;
|
|
394
|
+
}
|
|
395
|
+
if(error.original) {
|
|
396
|
+
delete error.original.sql;
|
|
397
|
+
}
|
|
398
|
+
if(error.parameters) {
|
|
399
|
+
delete error.parameters;
|
|
400
|
+
}
|
|
401
|
+
return cb(error, null);
|
|
402
|
+
} else {
|
|
403
|
+
return cb(String(error), null);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
348
406
|
}
|
|
349
407
|
} else {
|
|
350
408
|
cb({ error: "The Base pool error. UNKNOWN pool_base = '"+ pool_base +"'" }, null);
|
|
@@ -438,7 +496,28 @@ module.exports = {
|
|
|
438
496
|
data.facebook = profile;
|
|
439
497
|
cb(err, data);
|
|
440
498
|
} catch (error) {
|
|
441
|
-
|
|
499
|
+
if(pool.options.logging) {
|
|
500
|
+
return cb(error, null);
|
|
501
|
+
} else {
|
|
502
|
+
if(error.sql) {
|
|
503
|
+
delete error.sql;
|
|
504
|
+
if(error.errors) {
|
|
505
|
+
delete error.errors;
|
|
506
|
+
}
|
|
507
|
+
if(error.parent) {
|
|
508
|
+
delete error.parent;
|
|
509
|
+
}
|
|
510
|
+
if(error.original) {
|
|
511
|
+
delete error.original.sql;
|
|
512
|
+
}
|
|
513
|
+
if(error.parameters) {
|
|
514
|
+
delete error.parameters;
|
|
515
|
+
}
|
|
516
|
+
return cb(error, null);
|
|
517
|
+
} else {
|
|
518
|
+
return cb(String(error), null);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
442
521
|
}
|
|
443
522
|
} else {
|
|
444
523
|
cb({ error: "The Base pool error. UNKNOWN pool_base = '"+ pool_base +"'" }, null);
|
|
@@ -480,7 +559,28 @@ module.exports = {
|
|
|
480
559
|
});
|
|
481
560
|
return cb(null, JSON.parse(JSON.stringify(result || null)));
|
|
482
561
|
} catch (error) {
|
|
483
|
-
|
|
562
|
+
if(pool.options.logging) {
|
|
563
|
+
return cb(error, null);
|
|
564
|
+
} else {
|
|
565
|
+
if(error.sql) {
|
|
566
|
+
delete error.sql;
|
|
567
|
+
if(error.errors) {
|
|
568
|
+
delete error.errors;
|
|
569
|
+
}
|
|
570
|
+
if(error.parent) {
|
|
571
|
+
delete error.parent;
|
|
572
|
+
}
|
|
573
|
+
if(error.original) {
|
|
574
|
+
delete error.original.sql;
|
|
575
|
+
}
|
|
576
|
+
if(error.parameters) {
|
|
577
|
+
delete error.parameters;
|
|
578
|
+
}
|
|
579
|
+
return cb(error, null);
|
|
580
|
+
} else {
|
|
581
|
+
return cb(String(error), null);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
484
584
|
}
|
|
485
585
|
} else {
|
|
486
586
|
return done({ error: "The Base pool error. UNKNOWN pool_base = '"+ pool_base +"'" }, null);
|
|
@@ -15,8 +15,8 @@ module.exports = {
|
|
|
15
15
|
app_key: [ "2cc118cd91b52ff99e3c005ddced76fb" ]
|
|
16
16
|
},
|
|
17
17
|
|
|
18
|
-
//
|
|
19
|
-
|
|
18
|
+
// Job Scheduler it's work when enabled. You can enable scheduler by run CMD `$ beech skd init`.
|
|
19
|
+
scheduler: true,
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Database configuration (mutiple connection) currenty support for MySQL
|
|
@@ -15,8 +15,8 @@ module.exports = {
|
|
|
15
15
|
app_key: [ "2cc118cd91b52ff99e3c005ddced76fb" ]
|
|
16
16
|
},
|
|
17
17
|
|
|
18
|
-
//
|
|
19
|
-
|
|
18
|
+
// Job Scheduler it's work when enabled. You can enable scheduler by run CMD `$ beech skd init`.
|
|
19
|
+
scheduler: true,
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* The Database configuration (mutiple connection) currenty support for MySQL, SQLite, MariaDB, PostgreSQL and Microsoft SQL Server
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
// Allow using jwt
|
|
2
|
+
// Allow for using jwt
|
|
3
3
|
jwt_allow: true,
|
|
4
4
|
|
|
5
5
|
// Custom authenticaiton endpoint, default `/authentication`
|
|
@@ -11,6 +11,11 @@ module.exports = {
|
|
|
11
11
|
// Set token expiry time (seconds), default expired in 24 hr.
|
|
12
12
|
token_expired: 86400,
|
|
13
13
|
|
|
14
|
+
// Allow for using global jwt broken role
|
|
15
|
+
jwt_broken_role: [
|
|
16
|
+
// { role: [1, 2, 9] },
|
|
17
|
+
],
|
|
18
|
+
|
|
14
19
|
model: {
|
|
15
20
|
// Main sql connection name. You must make sure connection name like inside `app.config.js` file and choose one connection name.
|
|
16
21
|
name: "default_db",
|
|
@@ -20,22 +25,37 @@ module.exports = {
|
|
|
20
25
|
username_field: "",
|
|
21
26
|
password_field: "",
|
|
22
27
|
// JWT playload data
|
|
23
|
-
fields: []
|
|
28
|
+
fields: [],
|
|
29
|
+
// Other fields add for authentication.
|
|
30
|
+
guard: {
|
|
31
|
+
// Basic guard field, Example: ["pin", "email", "2fa"]
|
|
32
|
+
guard_field: [],
|
|
33
|
+
// Advanced guard jwt request (needed some logical from front-end)
|
|
34
|
+
advanced_guard: {
|
|
35
|
+
allow: false,
|
|
36
|
+
entity: "", // default entity `timing`
|
|
37
|
+
secret: "top_secret",
|
|
38
|
+
time_expired: {
|
|
39
|
+
minutes: 1, // should length [0-60]
|
|
40
|
+
seconds: 0, // should length [0-60]
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
24
44
|
},
|
|
25
45
|
|
|
26
|
-
// Allow using with app_key
|
|
46
|
+
// Allow for using request with app_key entity (Every request must be using the app_key entity in headers)
|
|
27
47
|
app_key_allow: true,
|
|
28
48
|
|
|
29
49
|
// Official strategy
|
|
30
50
|
strategy: {
|
|
31
51
|
/**
|
|
32
52
|
* The Client Id and Client Secret needed to authenticate with Google can be set up from the Google Developers Console (https://console.developers.google.com/)
|
|
33
|
-
* You may also need to enable Google API in the developer console, otherwise user profile data may not be fetched.
|
|
53
|
+
* You may also need to enable Google API in the developer console, otherwise user profile data may not be fetched.
|
|
34
54
|
* Now Google supports authentication with oAuth 2.0.
|
|
35
|
-
*
|
|
55
|
+
*
|
|
36
56
|
*/
|
|
37
57
|
google: {
|
|
38
|
-
// Allow using google strategy
|
|
58
|
+
// Allow for using google strategy
|
|
39
59
|
allow: false,
|
|
40
60
|
// Authen profile store fields available: `google_id`, `name`, `email`, `photos`, `locate`
|
|
41
61
|
local_profile_fields: {
|
|
@@ -47,19 +67,19 @@ module.exports = {
|
|
|
47
67
|
// Callback endpoint default `/google/callback`
|
|
48
68
|
callbackURL: "",
|
|
49
69
|
// Failure redirect to your route
|
|
50
|
-
failureRedirect: "/login"
|
|
70
|
+
failureRedirect: "/login",
|
|
51
71
|
},
|
|
52
72
|
|
|
53
73
|
/**
|
|
54
74
|
* The Facebook strategy allows users to log in to a web application using their Facebook account. Internally, Facebook authentication works using OAuth 2.0.
|
|
55
75
|
* Support for Facebook is implemented by the passport-facebook (https://github.com/jaredhanson/passport-facebook) module.
|
|
56
|
-
*
|
|
76
|
+
*
|
|
57
77
|
* In order to use Facebook authentication, you must first create an app at Facebook Developers. (https://developers.facebook.com/apps) When created, an app is assigned an App ID and App Secret.
|
|
58
78
|
* Your application must also implement a redirect URL, to which Facebook will redirect users after they have approved access for your application.
|
|
59
|
-
*
|
|
79
|
+
*
|
|
60
80
|
*/
|
|
61
81
|
facebook: {
|
|
62
|
-
// Allow using facebook strategy
|
|
82
|
+
// Allow for using facebook strategy
|
|
63
83
|
allow: false,
|
|
64
84
|
// Authen profile store fields available: `facebook_id`, `name`, `email`, `photos`, `locate`
|
|
65
85
|
local_profile_fields: {
|
|
@@ -71,7 +91,7 @@ module.exports = {
|
|
|
71
91
|
// Callback endpoint default `/facebook/callback`
|
|
72
92
|
callbackURL: "",
|
|
73
93
|
// Failure redirect to your route
|
|
74
|
-
failureRedirect: "/login"
|
|
94
|
+
failureRedirect: "/login",
|
|
75
95
|
},
|
|
76
|
-
}
|
|
77
|
-
}
|
|
96
|
+
},
|
|
97
|
+
};
|