@tachybase/plugin-auth-wecom 1.6.0 → 1.6.3
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/dist/externalVersion.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
"react": "18.3.1",
|
|
3
|
-
"@tachybase/client": "1.6.
|
|
4
|
-
"@ant-design/icons": "
|
|
3
|
+
"@tachybase/client": "1.6.3",
|
|
4
|
+
"@ant-design/icons": "6.1.0",
|
|
5
5
|
"antd": "5.22.5",
|
|
6
6
|
"react-router-dom": "6.28.1",
|
|
7
|
-
"@tachybase/module-auth": "1.6.
|
|
8
|
-
"@tego/server": "1.
|
|
7
|
+
"@tachybase/module-auth": "1.6.3",
|
|
8
|
+
"@tego/server": "1.6.1",
|
|
9
9
|
"axios": "1.13.0"
|
|
10
10
|
};
|
|
@@ -42,7 +42,7 @@ const redirect = async (ctx, next) => {
|
|
|
42
42
|
prefix += `apps/${appName}`;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
const auth = await ctx.
|
|
45
|
+
const auth = await ctx.tego.authManager.get(authenticator, ctx);
|
|
46
46
|
if (prefix.endsWith("/")) {
|
|
47
47
|
prefix = prefix.slice(0, -1);
|
|
48
48
|
}
|
|
File without changes
|
package/dist/server/work-auth.js
CHANGED
|
@@ -30,7 +30,8 @@ class WorkAuth extends import_server.BaseAuth {
|
|
|
30
30
|
const { ctx } = config;
|
|
31
31
|
super({
|
|
32
32
|
...config,
|
|
33
|
-
userCollection: ctx.db.getCollection("users")
|
|
33
|
+
userCollection: ctx.db.getCollection("users"),
|
|
34
|
+
userStatusCollection: ctx.db.getCollection("userStatuses")
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
async validate() {
|
|
@@ -84,7 +85,7 @@ class WorkAuth extends import_server.BaseAuth {
|
|
|
84
85
|
var _a, _b, _c, _d;
|
|
85
86
|
const clientId = (_b = (_a = this.options) == null ? void 0 : _a.workWeChat) == null ? void 0 : _b.corpId;
|
|
86
87
|
const agentId = (_d = (_c = this.options) == null ? void 0 : _c.workWeChat) == null ? void 0 : _d.agentId;
|
|
87
|
-
const app = this.ctx.
|
|
88
|
+
const app = this.ctx.tego.name;
|
|
88
89
|
const redirectUrl = encodeURIComponent(
|
|
89
90
|
`${this.ctx.protocol}://${this.ctx.host}${process.env.API_BASE_PATH}workWeChat:redirect`
|
|
90
91
|
);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Context } from '@tego/server';
|
|
1
2
|
interface Config {
|
|
2
3
|
clientId: string;
|
|
3
4
|
clientSecret: string;
|
|
@@ -5,9 +6,10 @@ interface Config {
|
|
|
5
6
|
}
|
|
6
7
|
export declare class WorkClient {
|
|
7
8
|
config: Config;
|
|
8
|
-
ctx:
|
|
9
|
+
ctx: Context;
|
|
9
10
|
accessToken: string;
|
|
10
11
|
tokenExpiresAt: number;
|
|
12
|
+
private readonly weComApiBaseUrl;
|
|
11
13
|
constructor(config: Config);
|
|
12
14
|
private fetchNewAccessToken;
|
|
13
15
|
getAccessToken(): Promise<string>;
|
|
@@ -35,13 +35,14 @@ class WorkClient {
|
|
|
35
35
|
constructor(config) {
|
|
36
36
|
this.accessToken = "";
|
|
37
37
|
this.tokenExpiresAt = 0;
|
|
38
|
+
this.weComApiBaseUrl = "https://qyapi.weixin.qq.com/cgi-bin/";
|
|
38
39
|
this.config = config;
|
|
39
|
-
this.ctx = config
|
|
40
|
+
this.ctx = config.ctx;
|
|
40
41
|
}
|
|
41
42
|
async fetchNewAccessToken() {
|
|
42
43
|
try {
|
|
43
44
|
const response = await import_axios.default.get(
|
|
44
|
-
|
|
45
|
+
`${this.weComApiBaseUrl}gettoken?corpid=${this.config.clientId}&corpsecret=${this.config.clientSecret}`
|
|
45
46
|
);
|
|
46
47
|
const data = response.data;
|
|
47
48
|
this.accessToken = data.access_token;
|
|
@@ -58,24 +59,24 @@ class WorkClient {
|
|
|
58
59
|
return this.accessToken;
|
|
59
60
|
}
|
|
60
61
|
async getUserInfo(accessToken, code) {
|
|
61
|
-
var _a, _b
|
|
62
|
+
var _a, _b;
|
|
62
63
|
try {
|
|
63
64
|
const response = await import_axios.default.get(
|
|
64
|
-
|
|
65
|
+
`${this.weComApiBaseUrl}user/getuserinfo?access_token=${accessToken}&code=${code}`
|
|
65
66
|
);
|
|
66
67
|
const userId = response.data.UserId;
|
|
67
68
|
if (userId) {
|
|
68
69
|
const userDetailResponse = await import_axios.default.post(
|
|
69
|
-
|
|
70
|
+
`${this.weComApiBaseUrl}user/get?access_token=${accessToken}&userid=${userId}`
|
|
70
71
|
);
|
|
71
72
|
return userDetailResponse.data;
|
|
72
73
|
} else {
|
|
73
|
-
|
|
74
|
+
this.ctx.logger.debug(`get userInfo error message: ${response.data.errmsg}`);
|
|
74
75
|
return {};
|
|
75
76
|
}
|
|
76
77
|
} catch (err) {
|
|
77
|
-
if ((
|
|
78
|
-
|
|
78
|
+
if ((_b = (_a = err.response) == null ? void 0 : _a.data) == null ? void 0 : _b.errmsg) {
|
|
79
|
+
this.ctx.logger.debug(`get userInfo error message: ${err.response.data.errmsg}`);
|
|
79
80
|
}
|
|
80
81
|
return {};
|
|
81
82
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tachybase/plugin-auth-wecom",
|
|
3
3
|
"displayName": "Auth: WeCom",
|
|
4
|
-
"version": "1.6.
|
|
4
|
+
"version": "1.6.3",
|
|
5
5
|
"description": "work WeChat authentication.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"Authentication"
|
|
@@ -9,16 +9,16 @@
|
|
|
9
9
|
"main": "dist/server/index.js",
|
|
10
10
|
"dependencies": {},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@ant-design/icons": "^
|
|
13
|
-
"@tachybase/test": "1.
|
|
14
|
-
"@tego/client": "1.
|
|
15
|
-
"@tego/server": "1.
|
|
12
|
+
"@ant-design/icons": "^6.1.0",
|
|
13
|
+
"@tachybase/test": "1.6.1",
|
|
14
|
+
"@tego/client": "1.6.1",
|
|
15
|
+
"@tego/server": "1.6.1",
|
|
16
16
|
"ahooks": "^3.9.0",
|
|
17
17
|
"antd": "5.22.5",
|
|
18
18
|
"axios": "1.13.0",
|
|
19
19
|
"react-router-dom": "6.28.1",
|
|
20
|
-
"@tachybase/client": "1.6.
|
|
21
|
-
"@tachybase/module-auth": "1.6.
|
|
20
|
+
"@tachybase/client": "1.6.3",
|
|
21
|
+
"@tachybase/module-auth": "1.6.3"
|
|
22
22
|
},
|
|
23
23
|
"description.zh-CN": "提供企业微信的认证支持",
|
|
24
24
|
"displayName.zh-CN": "认证:企业微信",
|