@steedos/accounts 3.0.0-beta.13 → 3.0.0-beta.131
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
|
@@ -1,71 +1,81 @@
|
|
|
1
|
-
import * as express from
|
|
2
|
-
import { get, isEmpty, map } from
|
|
3
|
-
import { AccountsServer } from
|
|
4
|
-
import { db } from
|
|
5
|
-
import { getSteedosConfig } from
|
|
6
|
-
import { getSteedosService } from
|
|
1
|
+
import * as express from "express";
|
|
2
|
+
import { get, isEmpty, map } from "lodash";
|
|
3
|
+
import { AccountsServer } from "../server";
|
|
4
|
+
import { db } from "../db";
|
|
5
|
+
import { getSteedosConfig } from "@steedos/objectql";
|
|
6
|
+
import { getSteedosService } from "../core";
|
|
7
7
|
const config = getSteedosConfig();
|
|
8
8
|
|
|
9
|
-
export const userLoader =
|
|
10
|
-
|
|
11
|
-
res: express.Response,
|
|
12
|
-
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
get(req.headers, 'Authorization') ||
|
|
17
|
-
get(req.headers, 'authorization');
|
|
9
|
+
export const userLoader =
|
|
10
|
+
(accountsServer: AccountsServer) =>
|
|
11
|
+
async (req: express.Request, res: express.Response, next: any) => {
|
|
12
|
+
let authToken =
|
|
13
|
+
get(req.cookies, "X-Auth-Token") ||
|
|
14
|
+
get(req.headers, "Authorization") ||
|
|
15
|
+
get(req.headers, "authorization");
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
authToken =
|
|
18
|
+
authToken && authToken.replace("Bearer ", "").replace("BEARER ", "");
|
|
19
|
+
authToken =
|
|
20
|
+
authToken && authToken.split(",").length > 1
|
|
21
|
+
? authToken.split(",")[0]
|
|
22
|
+
: authToken;
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const userSpaces = await db.find("space_users", {
|
|
36
|
-
filters: [["user", "=", user.id],["user_accepted", "=", true]],
|
|
37
|
-
fields: ["space"],
|
|
24
|
+
if (!isEmpty(authToken)) {
|
|
25
|
+
try {
|
|
26
|
+
(req as any).authToken = authToken;
|
|
27
|
+
const user: any = await accountsServer.resumeSession(authToken);
|
|
28
|
+
user.id = user._id;
|
|
29
|
+
user.userId = user._id;
|
|
30
|
+
if (user.emails && user.emails.length > 0) {
|
|
31
|
+
user.email = user.emails[0].address;
|
|
32
|
+
}
|
|
33
|
+
(req as any).user = user;
|
|
34
|
+
(req as any).userId = user.id;
|
|
35
|
+
const spaces = [];
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
const userSpaces = await db.find("space_users", {
|
|
38
|
+
filters: [
|
|
39
|
+
["user", "=", user.id],
|
|
40
|
+
["user_accepted", "=", true],
|
|
41
|
+
],
|
|
42
|
+
fields: ["space"],
|
|
43
|
+
});
|
|
40
44
|
|
|
41
|
-
|
|
45
|
+
let steedosService = getSteedosService();
|
|
42
46
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
if (userSpaces && userSpaces.length > 0) {
|
|
48
|
+
const dbSpaces = await db.find("spaces", {
|
|
49
|
+
filters: [["_id", "in", map(userSpaces, "space")]],
|
|
50
|
+
fields: ["_id", "name", "avatar", "avatar_dark"],
|
|
51
|
+
});
|
|
48
52
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
for (let space of dbSpaces) {
|
|
54
|
+
let logo_url = "";
|
|
55
|
+
if (steedosService) {
|
|
56
|
+
if (space.avatar_dark) {
|
|
57
|
+
logo_url =
|
|
58
|
+
steedosService +
|
|
59
|
+
"api/v6/files/cfs.avatars.filerecord/" +
|
|
60
|
+
space.avatar_dark;
|
|
61
|
+
} else if (space.avatar) {
|
|
62
|
+
logo_url =
|
|
63
|
+
steedosService +
|
|
64
|
+
"api/v6/files/cfs.avatars.filerecord/" +
|
|
65
|
+
space.avatar;
|
|
66
|
+
}
|
|
56
67
|
}
|
|
68
|
+
spaces.push({
|
|
69
|
+
_id: space._id,
|
|
70
|
+
name: space.name,
|
|
71
|
+
logo_url,
|
|
72
|
+
});
|
|
57
73
|
}
|
|
58
|
-
spaces.push({
|
|
59
|
-
_id: space._id,
|
|
60
|
-
name: space.name,
|
|
61
|
-
logo_url
|
|
62
|
-
})
|
|
63
74
|
}
|
|
75
|
+
(req as any).user.spaces = spaces;
|
|
76
|
+
} catch (e) {
|
|
77
|
+
console.log(e);
|
|
64
78
|
}
|
|
65
|
-
(req as any).user.spaces = spaces
|
|
66
|
-
} catch (e) {
|
|
67
|
-
console.log(e);
|
|
68
79
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
80
|
+
return next();
|
|
81
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: 孙浩林 sunhaolin@steedos.com
|
|
3
|
+
* @Date: 2025-09-12 14:05:36
|
|
4
|
+
* @LastEditors: 孙浩林 sunhaolin@steedos.com
|
|
5
|
+
* @LastEditTime: 2025-09-12 14:08:08
|
|
6
|
+
* @FilePath: /steedos-platform-3.0/packages/accounts/src/rest-express/utils/getClientIp.ts
|
|
7
|
+
* @Description:
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import * as requestIp from "request-ip";
|
|
11
|
+
|
|
12
|
+
export const getClientIp = (req) => {
|
|
13
|
+
let ip = requestIp.getClientIp(req);
|
|
14
|
+
// 去掉 IPv6 前缀 ::ffff:
|
|
15
|
+
if (ip && ip.startsWith("::ffff:")) {
|
|
16
|
+
ip = ip.substring(7);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// IPv6 localhost 映射
|
|
20
|
+
if (ip === "::1") {
|
|
21
|
+
ip = "127.0.0.1";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return ip;
|
|
25
|
+
};
|