@cicctencent/midwayjs-base 1.0.45 → 1.0.46
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/guard/auth.d.ts +5 -0
- package/dist/guard/auth.js +24 -13
- package/package.json +2 -1
package/dist/guard/auth.d.ts
CHANGED
|
@@ -7,6 +7,11 @@ export declare class AuthGuard implements IGuard<Context> {
|
|
|
7
7
|
ssoOption: any;
|
|
8
8
|
authOption: {
|
|
9
9
|
ignores?: string | Array<RegExp | string>;
|
|
10
|
+
loginUrl?: string;
|
|
11
|
+
redirectParam?: string;
|
|
12
|
+
appIdParam?: string;
|
|
13
|
+
authCodeParam?: string | false;
|
|
14
|
+
cleanParams?: string[];
|
|
10
15
|
};
|
|
11
16
|
apiOption: any;
|
|
12
17
|
koa: any;
|
package/dist/guard/auth.js
CHANGED
|
@@ -61,13 +61,17 @@ let AuthGuard = class AuthGuard {
|
|
|
61
61
|
let errRes = null;
|
|
62
62
|
let session = null;
|
|
63
63
|
try {
|
|
64
|
-
const
|
|
65
|
-
|
|
64
|
+
const authCodeParam = this.authOption?.authCodeParam === false
|
|
65
|
+
? false
|
|
66
|
+
: this.authOption?.authCodeParam || 'auth_code';
|
|
67
|
+
const authCode = authCodeParam ? context.URL.searchParams.get(authCodeParam) : null;
|
|
68
|
+
if (authCode && authCodeParam) {
|
|
66
69
|
session = await this.sessionService.loginByCode(authCode);
|
|
67
70
|
if (session) {
|
|
68
71
|
(0, utils_1.setAuthToken)(context, session.id);
|
|
69
72
|
}
|
|
70
|
-
|
|
73
|
+
if (authCodeParam)
|
|
74
|
+
context.URL.searchParams.delete(authCodeParam);
|
|
71
75
|
context.URL.hostname = context.detect?.HOSTNAME || context.hostname;
|
|
72
76
|
context.redirect(context.URL.toString());
|
|
73
77
|
return;
|
|
@@ -124,17 +128,24 @@ let AuthGuard = class AuthGuard {
|
|
|
124
128
|
throw new error_code_1.BizError(error.ret, error.msg);
|
|
125
129
|
}
|
|
126
130
|
else {
|
|
127
|
-
const loginUrl = `${this.ssoOption?.baseUrl || this.koa?.globalPrefix || ''}/login`;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
const loginUrl = this.authOption?.loginUrl || `${this.ssoOption?.baseUrl || this.koa?.globalPrefix || ''}/login`;
|
|
132
|
+
const loginPath = new URL(loginUrl, `${context.protocol}://${context.host}`).pathname;
|
|
133
|
+
if (context.URL.pathname !== loginPath) {
|
|
134
|
+
const currentUrl = context.URL;
|
|
135
|
+
if (context.detect?.HOSTNAME && currentUrl.hostname !== context.detect.HOSTNAME) {
|
|
136
|
+
currentUrl.hostname = context.detect.HOSTNAME;
|
|
132
137
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
+
for (const param of this.authOption?.cleanParams || ['jv_auth_code', 'token', 'auth_code']) {
|
|
139
|
+
currentUrl.searchParams.delete(param);
|
|
140
|
+
}
|
|
141
|
+
const redirectParam = this.authOption?.redirectParam || 'url';
|
|
142
|
+
const appIdParam = this.authOption?.appIdParam === undefined ? 'appid' : this.authOption.appIdParam;
|
|
143
|
+
const targetUrl = new URL(loginUrl, `${context.protocol}://${context.host}`);
|
|
144
|
+
targetUrl.searchParams.set(redirectParam, currentUrl.toString());
|
|
145
|
+
if (appIdParam) {
|
|
146
|
+
targetUrl.searchParams.set(appIdParam, String(this.ssoOption?.appId || 0));
|
|
147
|
+
}
|
|
148
|
+
context.redirect(targetUrl.toString());
|
|
138
149
|
}
|
|
139
150
|
else {
|
|
140
151
|
context.redirect(loginUrl);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cicctencent/midwayjs-base",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.46",
|
|
4
4
|
"description": "基础框架,服务",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"@midwayjs/typeorm": "^3.20.24",
|
|
58
58
|
"@midwayjs/view-nunjucks": "^3.20.24",
|
|
59
59
|
"axios": "^1.18.1",
|
|
60
|
+
"browserslist": "^0.2.3",
|
|
60
61
|
"dayjs": "^1.11.21",
|
|
61
62
|
"dotenv": "^17.4.2",
|
|
62
63
|
"ip": "^2.0.1",
|