dbgate-api 5.2.0 → 5.2.1
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbgate-api",
|
|
3
3
|
"main": "src/index.js",
|
|
4
|
-
"version": "5.2.
|
|
4
|
+
"version": "5.2.1",
|
|
5
5
|
"homepage": "https://dbgate.org/",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"cors": "^2.8.5",
|
|
28
28
|
"cross-env": "^6.0.3",
|
|
29
29
|
"dbgate-query-splitter": "^4.9.3",
|
|
30
|
-
"dbgate-sqltree": "^5.2.
|
|
31
|
-
"dbgate-tools": "^5.2.
|
|
30
|
+
"dbgate-sqltree": "^5.2.1",
|
|
31
|
+
"dbgate-tools": "^5.2.1",
|
|
32
32
|
"debug": "^4.3.4",
|
|
33
33
|
"diff": "^5.0.0",
|
|
34
34
|
"diff2html": "^3.4.13",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@types/fs-extra": "^9.0.11",
|
|
71
71
|
"@types/lodash": "^4.14.149",
|
|
72
|
-
"dbgate-types": "^5.2.
|
|
72
|
+
"dbgate-types": "^5.2.1",
|
|
73
73
|
"env-cmd": "^10.1.0",
|
|
74
74
|
"node-loader": "^1.0.2",
|
|
75
75
|
"nodemon": "^2.0.2",
|
package/src/controllers/auth.js
CHANGED
|
@@ -62,11 +62,12 @@ module.exports = {
|
|
|
62
62
|
async oauthToken(params) {
|
|
63
63
|
const { redirectUri, code } = params;
|
|
64
64
|
|
|
65
|
+
const scopeParam = process.env.OAUTH_SCOPE ? `&scope=${process.env.OAUTH_SCOPE}` : '';
|
|
65
66
|
const resp = await axios.default.post(
|
|
66
67
|
`${process.env.OAUTH_TOKEN}`,
|
|
67
68
|
`grant_type=authorization_code&code=${encodeURIComponent(code)}&redirect_uri=${encodeURIComponent(
|
|
68
69
|
redirectUri
|
|
69
|
-
)}&client_id=${process.env.OAUTH_CLIENT_ID}&client_secret=${process.env.OAUTH_CLIENT_SECRET}`
|
|
70
|
+
)}&client_id=${process.env.OAUTH_CLIENT_ID}&client_secret=${process.env.OAUTH_CLIENT_SECRET}${scopeParam}`
|
|
70
71
|
);
|
|
71
72
|
|
|
72
73
|
const { access_token, refresh_token } = resp.data;
|
|
@@ -75,7 +76,10 @@ module.exports = {
|
|
|
75
76
|
|
|
76
77
|
console.log('User payload returned from OAUTH:', payload);
|
|
77
78
|
|
|
78
|
-
const login =
|
|
79
|
+
const login =
|
|
80
|
+
process.env.OAUTH_LOGIN_FIELD && payload && payload[process.env.OAUTH_LOGIN_FIELD]
|
|
81
|
+
? payload[process.env.OAUTH_LOGIN_FIELD]
|
|
82
|
+
: 'oauth';
|
|
79
83
|
|
|
80
84
|
if (
|
|
81
85
|
process.env.OAUTH_ALLOWED_LOGINS &&
|
|
@@ -113,7 +117,7 @@ module.exports = {
|
|
|
113
117
|
!process.env.AD_ALLOWED_LOGINS.split(',').find(x => x.toLowerCase().trim() == login.toLowerCase().trim())
|
|
114
118
|
) {
|
|
115
119
|
return { error: `Username ${login} not allowed to log in` };
|
|
116
|
-
}
|
|
120
|
+
}
|
|
117
121
|
return {
|
|
118
122
|
accessToken: jwt.sign({ login }, tokenSecret, { expiresIn: getTokenLifetime() }),
|
|
119
123
|
};
|
|
@@ -129,7 +133,7 @@ module.exports = {
|
|
|
129
133
|
if (!logins) {
|
|
130
134
|
return { error: 'Logins not configured' };
|
|
131
135
|
}
|
|
132
|
-
const foundLogin = logins.find(x => x.login == login)
|
|
136
|
+
const foundLogin = logins.find(x => x.login == login);
|
|
133
137
|
if (foundLogin && foundLogin.password == password) {
|
|
134
138
|
return {
|
|
135
139
|
accessToken: jwt.sign({ login }, tokenSecret, { expiresIn: getTokenLifetime() }),
|
|
@@ -28,12 +28,9 @@ module.exports = {
|
|
|
28
28
|
get_meta: true,
|
|
29
29
|
async get(_params, req) {
|
|
30
30
|
const logins = getLogins();
|
|
31
|
-
const
|
|
32
|
-
req && req.user
|
|
33
|
-
|
|
34
|
-
: logins
|
|
35
|
-
? logins.find(x => x.login == (req && req.auth && req.auth.user))
|
|
36
|
-
: null;
|
|
31
|
+
const loginName =
|
|
32
|
+
req && req.user && req.user.login ? req.user.login : req && req.auth && req.auth.user ? req.auth.user : null;
|
|
33
|
+
const login = logins && loginName ? logins.find(x => x.login == loginName) : null;
|
|
37
34
|
const permissions = login ? login.permissions : process.env.PERMISSIONS;
|
|
38
35
|
|
|
39
36
|
return {
|
|
@@ -47,6 +44,8 @@ module.exports = {
|
|
|
47
44
|
permissions,
|
|
48
45
|
login,
|
|
49
46
|
oauth: process.env.OAUTH_AUTH,
|
|
47
|
+
oauthClient: process.env.OAUTH_CLIENT_ID,
|
|
48
|
+
oauthScope: process.env.OAUTH_SCOPE,
|
|
50
49
|
oauthLogout: process.env.OAUTH_LOGOUT,
|
|
51
50
|
isLoginForm: !!process.env.AD_URL || (!!logins && !process.env.BASIC_AUTH),
|
|
52
51
|
...currentVersion,
|
|
@@ -47,6 +47,9 @@ module.exports = {
|
|
|
47
47
|
const existing = this.opened.find(x => x.conid == conid);
|
|
48
48
|
if (existing) return existing;
|
|
49
49
|
const connection = await connections.getCore({ conid });
|
|
50
|
+
if (!connection) {
|
|
51
|
+
throw new Error(`Connection with conid="${conid}" not fund`);
|
|
52
|
+
}
|
|
50
53
|
if (connection.passwordMode == 'askPassword' || connection.passwordMode == 'askUser') {
|
|
51
54
|
throw new MissingCredentialsError({ conid, passwordMode: connection.passwordMode });
|
|
52
55
|
}
|
|
@@ -110,6 +113,7 @@ module.exports = {
|
|
|
110
113
|
|
|
111
114
|
listDatabases_meta: true,
|
|
112
115
|
async listDatabases({ conid }, req) {
|
|
116
|
+
if (!conid) return [];
|
|
113
117
|
testConnectionPermission(conid, req);
|
|
114
118
|
const opened = await this.ensureOpened(conid);
|
|
115
119
|
return opened.databases;
|
package/src/currentVersion.js
CHANGED