@steedos/accounts 3.0.0-beta.15 → 3.0.0-beta.151
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/lib/core/index.js +87 -42
- package/lib/core/index.js.map +1 -1
- package/lib/rest-express/endpoints/authorize.js +2 -2
- package/lib/rest-express/endpoints/authorize.js.map +1 -1
- package/lib/rest-express/endpoints/impersonate.js +25 -23
- package/lib/rest-express/endpoints/impersonate.js.map +1 -1
- package/lib/rest-express/endpoints/login.js +95 -93
- package/lib/rest-express/endpoints/login.js.map +1 -1
- package/lib/rest-express/endpoints/logout.js +80 -73
- package/lib/rest-express/endpoints/logout.js.map +1 -1
- package/lib/rest-express/endpoints/oauth/provider-callback.js +35 -33
- package/lib/rest-express/endpoints/oauth/provider-callback.js.map +1 -1
- package/lib/rest-express/endpoints/password/change-password.js +95 -90
- package/lib/rest-express/endpoints/password/change-password.js.map +1 -1
- package/lib/rest-express/endpoints/refresh-access-token.js +25 -23
- package/lib/rest-express/endpoints/refresh-access-token.js.map +1 -1
- package/lib/rest-express/endpoints/service-authenticate.js +76 -74
- package/lib/rest-express/endpoints/service-authenticate.js.map +1 -1
- package/lib/rest-express/endpoints/steedos/get-tenant.js +62 -39
- package/lib/rest-express/endpoints/steedos/get-tenant.js.map +1 -1
- package/lib/rest-express/endpoints/steedos/settings.js +119 -88
- package/lib/rest-express/endpoints/steedos/settings.js.map +1 -1
- package/lib/rest-express/endpoints/update-session.js +44 -42
- package/lib/rest-express/endpoints/update-session.js.map +1 -1
- package/lib/rest-express/user-loader.js +82 -67
- package/lib/rest-express/user-loader.js.map +1 -1
- package/lib/rest-express/utils/getClientIp.js +16 -0
- package/lib/rest-express/utils/getClientIp.js.map +1 -0
- package/package.json +5 -6
- package/src/core/index.ts +197 -145
- package/src/rest-express/endpoints/authorize.ts +2 -2
- package/src/rest-express/endpoints/impersonate.ts +30 -31
- package/src/rest-express/endpoints/login.ts +66 -61
- package/src/rest-express/endpoints/logout.ts +74 -72
- package/src/rest-express/endpoints/oauth/provider-callback.ts +45 -38
- package/src/rest-express/endpoints/password/change-password.ts +94 -83
- package/src/rest-express/endpoints/refresh-access-token.ts +23 -24
- package/src/rest-express/endpoints/service-authenticate.ts +87 -68
- package/src/rest-express/endpoints/steedos/get-tenant.ts +56 -38
- package/src/rest-express/endpoints/steedos/settings.ts +117 -88
- package/src/rest-express/endpoints/update-session.ts +50 -42
- package/src/rest-express/user-loader.ts +68 -58
- package/src/rest-express/utils/getClientIp.ts +25 -0
|
@@ -3,80 +3,82 @@
|
|
|
3
3
|
* @Date: 2022-03-28 09:35:34
|
|
4
4
|
* @LastEditors: baozhoutao@steedos.com
|
|
5
5
|
* @LastEditTime: 2024-01-23 14:24:35
|
|
6
|
-
* @Description:
|
|
6
|
+
* @Description:
|
|
7
7
|
*/
|
|
8
|
-
import * as express from
|
|
9
|
-
import { get, isEmpty, map } from
|
|
10
|
-
import { AccountsServer } from
|
|
11
|
-
import { sendError } from
|
|
12
|
-
import { clearAuthCookies } from
|
|
13
|
-
import { getObject } from
|
|
14
|
-
import
|
|
15
|
-
import { getUserAgent } from
|
|
16
|
-
import isMobile from
|
|
17
|
-
import { getSteedosSchema } from
|
|
18
|
-
export const logout =
|
|
19
|
-
|
|
20
|
-
res: express.Response
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
get(req.headers, 'Authorization') ||
|
|
26
|
-
get(req.headers, 'authorization');
|
|
8
|
+
import * as express from "express";
|
|
9
|
+
import { get, isEmpty, map } from "lodash";
|
|
10
|
+
import { AccountsServer } from "../../server";
|
|
11
|
+
import { sendError } from "../utils/send-error";
|
|
12
|
+
import { clearAuthCookies } from "../utils/steedos-auth";
|
|
13
|
+
import { getObject } from "@steedos/objectql";
|
|
14
|
+
import { getClientIp } from "../utils/getClientIp";
|
|
15
|
+
import { getUserAgent } from "../utils/get-user-agent";
|
|
16
|
+
import isMobile from "ismobilejs";
|
|
17
|
+
import { getSteedosSchema } from "@steedos/objectql";
|
|
18
|
+
export const logout =
|
|
19
|
+
(accountsServer: AccountsServer) =>
|
|
20
|
+
async (req: express.Request, res: express.Response) => {
|
|
21
|
+
let authToken =
|
|
22
|
+
get(req.cookies, "X-Auth-Token") ||
|
|
23
|
+
get(req.headers, "Authorization") ||
|
|
24
|
+
get(req.headers, "authorization");
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
authToken = authToken && authToken.replace("Bearer ", "token");
|
|
27
|
+
authToken =
|
|
28
|
+
authToken && authToken.split(",").length > 1
|
|
29
|
+
? authToken.split(",")[0]
|
|
30
|
+
: authToken;
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
32
|
+
clearAuthCookies(req, res);
|
|
33
|
+
let session = null;
|
|
34
|
+
try {
|
|
35
|
+
session = await accountsServer.logout(authToken);
|
|
36
|
+
} catch (err) {
|
|
37
|
+
//sendError(res, err);
|
|
38
|
+
} finally {
|
|
39
|
+
let userAgent = getUserAgent(req) || "";
|
|
40
|
+
const ip = getClientIp(req);
|
|
41
|
+
let status = "success";
|
|
42
|
+
let message = "";
|
|
43
|
+
let is_phone = false;
|
|
44
|
+
let is_tablet = false;
|
|
45
|
+
if (userAgent) {
|
|
46
|
+
try {
|
|
47
|
+
const { phone, tablet } = isMobile(userAgent);
|
|
48
|
+
is_phone = phone;
|
|
49
|
+
is_tablet = tablet;
|
|
50
|
+
} catch (Exception) {
|
|
51
|
+
console.log(`Exception`, Exception);
|
|
52
|
+
}
|
|
51
53
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
54
|
+
await getObject("operation_logs").insert({
|
|
55
|
+
name: "注销",
|
|
56
|
+
type: "logout",
|
|
57
|
+
remote_user: session?.userId,
|
|
58
|
+
remote_addr: ip,
|
|
59
|
+
http_user_agent: userAgent,
|
|
60
|
+
is_mobile: is_phone,
|
|
61
|
+
is_tablet,
|
|
62
|
+
object: "users",
|
|
63
|
+
status: status,
|
|
64
|
+
create: new Date(),
|
|
65
|
+
space: session?.space,
|
|
66
|
+
message: message,
|
|
67
|
+
data: JSON.stringify({
|
|
68
|
+
authToken: authToken,
|
|
69
|
+
session: session,
|
|
70
|
+
}),
|
|
71
|
+
related_to: {
|
|
72
|
+
o: "users",
|
|
73
|
+
ids: [session?.userId],
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
if (authToken) {
|
|
77
|
+
const broker = getSteedosSchema().broker;
|
|
78
|
+
broker.broadcast("$user.logout", {
|
|
79
|
+
authToken: authToken,
|
|
80
|
+
});
|
|
73
81
|
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
broker.broadcast("$user.logout", {
|
|
78
|
-
authToken: authToken
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
res.json(null);
|
|
82
|
-
};
|
|
82
|
+
}
|
|
83
|
+
res.json(null);
|
|
84
|
+
};
|
|
@@ -1,46 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/*
|
|
2
|
+
* @Author: 孙浩林 sunhaolin@steedos.com
|
|
3
|
+
* @Date: 2025-02-17 09:39:59
|
|
4
|
+
* @LastEditors: 孙浩林 sunhaolin@steedos.com
|
|
5
|
+
* @LastEditTime: 2025-09-12 14:29:52
|
|
6
|
+
* @FilePath: /steedos-platform-3.0/packages/accounts/src/rest-express/endpoints/oauth/provider-callback.ts
|
|
7
|
+
* @Description:
|
|
8
|
+
*/
|
|
9
|
+
import * as express from "express";
|
|
10
|
+
import { getClientIp } from "../../utils/getClientIp";
|
|
11
|
+
import { AccountsServer } from "../../../server";
|
|
12
|
+
import { getUserAgent } from "../../utils/get-user-agent";
|
|
13
|
+
import { sendError } from "../../utils/send-error";
|
|
14
|
+
import { AccountsExpressOptions } from "../../types";
|
|
7
15
|
|
|
8
16
|
interface RequestWithSession extends express.Request {
|
|
9
17
|
session: any;
|
|
10
18
|
}
|
|
11
19
|
|
|
12
|
-
export const providerCallback =
|
|
13
|
-
accountsServer: AccountsServer,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
);
|
|
20
|
+
export const providerCallback =
|
|
21
|
+
(accountsServer: AccountsServer, options?: AccountsExpressOptions) =>
|
|
22
|
+
async (req: express.Request, res: express.Response) => {
|
|
23
|
+
try {
|
|
24
|
+
const userAgent = getUserAgent(req);
|
|
25
|
+
const ip = getClientIp(req);
|
|
26
|
+
const loggedInUser = await accountsServer.loginWithService(
|
|
27
|
+
"oauth",
|
|
28
|
+
{
|
|
29
|
+
...(req.params || {}),
|
|
30
|
+
...(req.query || {}),
|
|
31
|
+
...(req.body || {}),
|
|
32
|
+
...((req as RequestWithSession).session || {}),
|
|
33
|
+
},
|
|
34
|
+
{ ip, userAgent },
|
|
35
|
+
);
|
|
29
36
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
if (options && options.onOAuthSuccess) {
|
|
38
|
+
options.onOAuthSuccess(req, res, loggedInUser);
|
|
39
|
+
}
|
|
33
40
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
if (options && options.transformOAuthResponse) {
|
|
42
|
+
res.json(options.transformOAuthResponse(loggedInUser));
|
|
43
|
+
} else {
|
|
44
|
+
res.json(loggedInUser);
|
|
45
|
+
}
|
|
46
|
+
} catch (err) {
|
|
47
|
+
if (options && options.onOAuthError) {
|
|
48
|
+
options.onOAuthError(req, res, err);
|
|
49
|
+
}
|
|
43
50
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
};
|
|
51
|
+
sendError(res, err);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
@@ -1,103 +1,114 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* @Author: baozhoutao@steedos.com
|
|
3
3
|
* @Date: 2022-05-19 11:38:30
|
|
4
|
-
* @LastEditors:
|
|
5
|
-
* @LastEditTime:
|
|
6
|
-
* @Description:
|
|
4
|
+
* @LastEditors: 孙浩林 sunhaolin@steedos.com
|
|
5
|
+
* @LastEditTime: 2025-09-12 14:29:58
|
|
6
|
+
* @Description:
|
|
7
7
|
*/
|
|
8
|
-
import * as express from
|
|
9
|
-
import { AccountsServer } from
|
|
10
|
-
import { sendError } from
|
|
11
|
-
import { getSteedosConfig, getObject } from
|
|
12
|
-
import { hashPassword } from
|
|
8
|
+
import * as express from "express";
|
|
9
|
+
import { AccountsServer } from "../../../server";
|
|
10
|
+
import { sendError } from "../../utils/send-error";
|
|
11
|
+
import { getSteedosConfig, getObject } from "@steedos/objectql";
|
|
12
|
+
import { hashPassword } from "../../../password/utils";
|
|
13
13
|
|
|
14
|
-
import
|
|
15
|
-
import { getUserAgent } from
|
|
14
|
+
import { getClientIp } from "../../utils/getClientIp";
|
|
15
|
+
import { getUserAgent } from "../../utils/get-user-agent";
|
|
16
16
|
import isMobile from "ismobilejs";
|
|
17
|
-
import { db } from
|
|
17
|
+
import { db } from "../../../db";
|
|
18
18
|
|
|
19
19
|
const config = getSteedosConfig();
|
|
20
20
|
declare var Creator;
|
|
21
21
|
|
|
22
|
-
export const changePassword =
|
|
23
|
-
|
|
24
|
-
res: express.Response
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const { oldPassword, newPassword } = req.body;
|
|
22
|
+
export const changePassword =
|
|
23
|
+
(accountsServer: AccountsServer) =>
|
|
24
|
+
async (req: express.Request, res: express.Response) => {
|
|
25
|
+
try {
|
|
26
|
+
if (!(req as any).userId) {
|
|
27
|
+
res.status(401);
|
|
28
|
+
res.json({ message: "Unauthorized" });
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// oldPassword 、newPassword 已经是 sha256之后的
|
|
32
|
+
const { oldPassword, newPassword } = req.body;
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
// let passworPolicy = ((config as any).password || {}).policy
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const password: any = accountsServer.getServices().password;
|
|
36
|
+
// if(passworPolicy){
|
|
37
|
+
// if(!(new RegExp(passworPolicy)).test(newPassword || '')){
|
|
38
|
+
// sendError(res, new Error((config as any).password.policyError));
|
|
39
|
+
// return;
|
|
40
|
+
// }
|
|
41
|
+
// }
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
const password: any = accountsServer.getServices().password;
|
|
44
|
+
|
|
45
|
+
await password.changePassword(
|
|
46
|
+
(req as any).userId,
|
|
47
|
+
oldPassword,
|
|
48
|
+
newPassword,
|
|
49
|
+
);
|
|
50
|
+
password.db.collection.updateOne(
|
|
51
|
+
{ _id: (req as any).userId },
|
|
52
|
+
{ $set: { password_expired: false } },
|
|
53
|
+
);
|
|
54
|
+
try {
|
|
55
|
+
await db.updateMany(
|
|
56
|
+
"space_users",
|
|
57
|
+
[["user", "=", (req as any).userId]],
|
|
58
|
+
{ password_expired: false },
|
|
59
|
+
);
|
|
52
60
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const userAgent = getUserAgent(req);
|
|
62
|
+
const ip = getClientIp(req);
|
|
63
|
+
let is_phone = false;
|
|
64
|
+
let is_tablet = false;
|
|
65
|
+
if (userAgent) {
|
|
66
|
+
try {
|
|
67
|
+
const { phone, tablet } = isMobile(userAgent);
|
|
68
|
+
is_phone = phone;
|
|
69
|
+
is_tablet = tablet;
|
|
70
|
+
} catch (Exception) {
|
|
71
|
+
console.log(`Exception`, Exception);
|
|
72
|
+
}
|
|
64
73
|
}
|
|
65
|
-
}
|
|
66
74
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
const userSpaces = await db.find("space_users", {
|
|
76
|
+
filters: [
|
|
77
|
+
["user", "=", (req as any).userId],
|
|
78
|
+
["user_accepted", "=", true],
|
|
79
|
+
],
|
|
80
|
+
fields: ["space"],
|
|
81
|
+
});
|
|
71
82
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
if (userSpaces && userSpaces.length > 0) {
|
|
84
|
+
for (let userSpace of userSpaces) {
|
|
85
|
+
const userId = (req as any).userId;
|
|
86
|
+
await getObject("operation_logs").insert({
|
|
87
|
+
name: "修改密码",
|
|
88
|
+
type: "change_password",
|
|
89
|
+
remote_user: userId,
|
|
90
|
+
remote_addr: ip,
|
|
91
|
+
http_user_agent: userAgent,
|
|
92
|
+
is_mobile: is_phone,
|
|
93
|
+
is_tablet,
|
|
94
|
+
object: "users",
|
|
95
|
+
status: "success",
|
|
96
|
+
create: new Date(),
|
|
97
|
+
create_by: userId,
|
|
98
|
+
modified_by: userId,
|
|
99
|
+
space: userSpace.space,
|
|
100
|
+
related_to: {
|
|
101
|
+
o: "users",
|
|
102
|
+
ids: [userId],
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
94
106
|
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.log("error", error);
|
|
95
109
|
}
|
|
96
|
-
|
|
97
|
-
|
|
110
|
+
res.json({ userId: (req as any).userId, password_expired: false });
|
|
111
|
+
} catch (err) {
|
|
112
|
+
sendError(res, err);
|
|
98
113
|
}
|
|
99
|
-
|
|
100
|
-
} catch (err) {
|
|
101
|
-
sendError(res, err);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
114
|
+
};
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
import * as express from
|
|
2
|
-
import
|
|
3
|
-
import { AccountsServer } from
|
|
4
|
-
import { getUserAgent } from
|
|
5
|
-
import { sendError } from
|
|
1
|
+
import * as express from "express";
|
|
2
|
+
import { getClientIp } from "../utils/getClientIp";
|
|
3
|
+
import { AccountsServer } from "../../server";
|
|
4
|
+
import { getUserAgent } from "../utils/get-user-agent";
|
|
5
|
+
import { sendError } from "../utils/send-error";
|
|
6
6
|
|
|
7
|
-
export const refreshAccessToken =
|
|
8
|
-
|
|
9
|
-
res: express.Response
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
};
|
|
7
|
+
export const refreshAccessToken =
|
|
8
|
+
(accountsServer: AccountsServer) =>
|
|
9
|
+
async (req: express.Request, res: express.Response) => {
|
|
10
|
+
try {
|
|
11
|
+
const { accessToken, refreshToken } = req.body;
|
|
12
|
+
const userAgent = getUserAgent(req);
|
|
13
|
+
const ip = getClientIp(req);
|
|
14
|
+
const refreshedSession = await accountsServer.refreshTokens(
|
|
15
|
+
accessToken,
|
|
16
|
+
refreshToken,
|
|
17
|
+
ip,
|
|
18
|
+
userAgent,
|
|
19
|
+
);
|
|
20
|
+
res.json(refreshedSession);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
sendError(res, err);
|
|
23
|
+
}
|
|
24
|
+
};
|