cloud-web-corejs 1.1.0-dev.90 → 1.1.0-dev.92
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 +1 -1
- package/src/api/user.js +9 -0
- package/src/layout/components/Sidebar/default.vue +1 -0
- package/src/permission.js +18 -1
- package/src/store/modules/user.js +28 -2
- package/src/utils/customSsoUtil.js +66 -0
- package/src/views/user/home/default2.vue +1 -0
- package/src/views/user/login/indexMixin.js +155 -0
package/package.json
CHANGED
package/src/api/user.js
CHANGED
|
@@ -134,3 +134,12 @@ export function getIdmLoginUrl(option) {
|
|
|
134
134
|
...option,
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
|
+
|
|
138
|
+
export function getCustomLoginConfig(option) {
|
|
139
|
+
return request({
|
|
140
|
+
url: USER_PREFIX + "/bd_api/intf/customLoginConfig",
|
|
141
|
+
method: "post",
|
|
142
|
+
useToken: false,
|
|
143
|
+
...option,
|
|
144
|
+
});
|
|
145
|
+
}
|
package/src/permission.js
CHANGED
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
import NProgress from "nprogress"; // progress bar
|
|
8
8
|
import "nprogress/nprogress.css"; // progress bar style
|
|
9
9
|
import {
|
|
10
|
-
getToken
|
|
10
|
+
getToken,
|
|
11
|
+
removeToken
|
|
11
12
|
} from "./utils/auth"; // get token from cookie
|
|
12
13
|
import settingConfig from "@/settings";
|
|
13
14
|
|
|
@@ -36,6 +37,22 @@ router.beforeEach((to, from, next) => {
|
|
|
36
37
|
next();
|
|
37
38
|
});
|
|
38
39
|
|
|
40
|
+
// 自定义单点回调:URL 上已有 code 时先清掉残留的旧 token,
|
|
41
|
+
// 否则守卫会在 hasToken 时把 /login 直接弹回 /,授权码永远得不到兑换。
|
|
42
|
+
let customSsoCallbackHandled = false;
|
|
43
|
+
router.beforeEach((to, from, next) => {
|
|
44
|
+
if (!customSsoCallbackHandled && settingConfig.defaultLoginMode === "customSso") {
|
|
45
|
+
customSsoCallbackHandled = true;
|
|
46
|
+
let queryCode = to && to.query && to.query.code;
|
|
47
|
+
let inUrl = /[?&]code=/.test(location.search) || /[?&]code=/.test(location.hash);
|
|
48
|
+
if ((queryCode || inUrl) && getToken()) {
|
|
49
|
+
removeToken();
|
|
50
|
+
store.commit("user/SET_TOKEN", "");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
next();
|
|
54
|
+
});
|
|
55
|
+
|
|
39
56
|
router.beforeEach((to, from, next) => {
|
|
40
57
|
// start progress bar
|
|
41
58
|
NProgress.start();
|
|
@@ -8,6 +8,11 @@ import {
|
|
|
8
8
|
getLoginConfig,
|
|
9
9
|
getLogicParamValue,
|
|
10
10
|
} from "../../api/user";
|
|
11
|
+
import {
|
|
12
|
+
isCustomSsoMode,
|
|
13
|
+
readSsoLogoutState,
|
|
14
|
+
fetchCustomSsoConfig,
|
|
15
|
+
} from "../../utils/customSsoUtil";
|
|
11
16
|
import { getToken, setToken, clearToken } from "../../utils/auth";
|
|
12
17
|
import { loadAesKeys, clearAesKeys } from "../../utils/aes";
|
|
13
18
|
import { clearBaseDictsCache } from "../../utils/baseDictsCache";
|
|
@@ -304,7 +309,10 @@ actions = {
|
|
|
304
309
|
return new Promise((resolve, reject) => {
|
|
305
310
|
configUtil.logout({
|
|
306
311
|
success: (res) => {
|
|
307
|
-
let
|
|
312
|
+
let ssoState = readSsoLogoutState();
|
|
313
|
+
let ssoLogin = ssoState.ssoLogin;
|
|
314
|
+
let ssoLogoutUrl = ssoState.logoutUrl;
|
|
315
|
+
let customSso = isCustomSsoMode();
|
|
308
316
|
actions
|
|
309
317
|
.resetToken({
|
|
310
318
|
commit,
|
|
@@ -312,7 +320,25 @@ actions = {
|
|
|
312
320
|
dispatch,
|
|
313
321
|
})
|
|
314
322
|
.then(() => {
|
|
315
|
-
if(ssoLogin
|
|
323
|
+
if (ssoLogin && customSso) {
|
|
324
|
+
const finish = (url) => {
|
|
325
|
+
if (url) {
|
|
326
|
+
location.href = url;
|
|
327
|
+
resolve({ customSsoRedirected: true });
|
|
328
|
+
} else {
|
|
329
|
+
resolve({ customSsoRedirected: false });
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
if (ssoLogoutUrl) {
|
|
333
|
+
finish(ssoLogoutUrl);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
fetchCustomSsoConfig().then((objx) => {
|
|
337
|
+
finish(objx && objx.logout_url);
|
|
338
|
+
});
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (ssoLogin) {
|
|
316
342
|
sessionStorage.setItem("ssoLogin", "true");
|
|
317
343
|
}
|
|
318
344
|
resolve();
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import settingConfig from "@/settings";
|
|
2
|
+
import { getCustomLoginConfig } from "@base/api/user";
|
|
3
|
+
|
|
4
|
+
export const CUSTOM_SSO_EXITED_KEY = "customSsoExited";
|
|
5
|
+
export const SSO_LOGIN_KEY = "ssoLogin";
|
|
6
|
+
export const SSO_LOGOUT_URL_KEY = "ssoLogoutUrl";
|
|
7
|
+
|
|
8
|
+
export function isCustomSsoMode() {
|
|
9
|
+
return settingConfig.defaultLoginMode === "customSso";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getCustomSsoOptions() {
|
|
13
|
+
let cfg = settingConfig.customSso || {};
|
|
14
|
+
return {
|
|
15
|
+
config: cfg.config || "hxIamLoginConfig",
|
|
16
|
+
codeField: cfg.codeField || "haixinSSOCode",
|
|
17
|
+
autoJump: cfg.autoJump === true,
|
|
18
|
+
localLoginRedirect: cfg.localLoginRedirect || "/home",
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** sessionStorage.clear 之前读取,登出后才能拿到 logout_url */
|
|
23
|
+
export function readSsoLogoutState() {
|
|
24
|
+
return {
|
|
25
|
+
ssoLogin: sessionStorage.getItem(SSO_LOGIN_KEY) === "true",
|
|
26
|
+
logoutUrl: sessionStorage.getItem(SSO_LOGOUT_URL_KEY) || "",
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function cacheSsoLogoutUrl(url) {
|
|
31
|
+
if (url) {
|
|
32
|
+
sessionStorage.setItem(SSO_LOGOUT_URL_KEY, url);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 仅 redirect=/home(或配置的 localLoginRedirect)时留在本地登录页 */
|
|
37
|
+
export function isCustomSsoLocalLogin(redirect) {
|
|
38
|
+
if (!redirect) return false;
|
|
39
|
+
let value = String(redirect);
|
|
40
|
+
try {
|
|
41
|
+
value = decodeURIComponent(value);
|
|
42
|
+
} catch (e) {
|
|
43
|
+
// ignore malformed encoding
|
|
44
|
+
}
|
|
45
|
+
let local = getCustomSsoOptions().localLoginRedirect || "/home";
|
|
46
|
+
return value === local;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function fetchCustomSsoConfig() {
|
|
50
|
+
let options = getCustomSsoOptions();
|
|
51
|
+
return new Promise((resolve) => {
|
|
52
|
+
getCustomLoginConfig({
|
|
53
|
+
data: { config: options.config },
|
|
54
|
+
isLoading: true,
|
|
55
|
+
failMsg: false,
|
|
56
|
+
errorMsg: false,
|
|
57
|
+
success: (res) => {
|
|
58
|
+
let objx = (res && res.objx) || {};
|
|
59
|
+
cacheSsoLogoutUrl(objx.logout_url);
|
|
60
|
+
resolve(objx);
|
|
61
|
+
},
|
|
62
|
+
fail: () => resolve({}),
|
|
63
|
+
error: () => resolve({}),
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { encode } from "js-base64";
|
|
2
2
|
import settingConfig from "@/settings";
|
|
3
3
|
import QRcode from "qrcode";
|
|
4
|
+
import { getToken, removeToken } from "@base/utils/auth";
|
|
5
|
+
import {
|
|
6
|
+
CUSTOM_SSO_EXITED_KEY,
|
|
7
|
+
getCustomSsoOptions,
|
|
8
|
+
isCustomSsoLocalLogin,
|
|
9
|
+
fetchCustomSsoConfig,
|
|
10
|
+
} from "@base/utils/customSsoUtil";
|
|
4
11
|
|
|
5
12
|
function getUrlParams(url) {
|
|
6
13
|
let result = {};
|
|
@@ -164,6 +171,13 @@ export default {
|
|
|
164
171
|
this.handleLoginConfig();
|
|
165
172
|
let searchParam = getUrlParams(location.search);
|
|
166
173
|
this.searchParam = searchParam;
|
|
174
|
+
|
|
175
|
+
// 自定义单点(如海信 IAM)与小熊/网关等入口互斥,走独立分支
|
|
176
|
+
if (settingConfig.defaultLoginMode === "customSso") {
|
|
177
|
+
this.initCustomSso();
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
167
181
|
//小熊SSO返回判断--目前因为小熊单点返回ticket有问题要特殊处理
|
|
168
182
|
let ssoParams = {};
|
|
169
183
|
if (location.search) {
|
|
@@ -337,6 +351,147 @@ export default {
|
|
|
337
351
|
this.initPassword();
|
|
338
352
|
this.showView = true;
|
|
339
353
|
},
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* 自定义单点(如海信 IAM)入口分派。
|
|
357
|
+
* 1. 回调带 code → 换 token(不受灰度标识约束)
|
|
358
|
+
* 2. login?redirect=/home(或配置的 localLoginRedirect)→ 本地登录页,优先于其它规则
|
|
359
|
+
* 3. 调试期 autoJump=false:需 ?sso=1 才跳第三方;上线后 autoJump=true 则默认跳转
|
|
360
|
+
*/
|
|
361
|
+
initCustomSso() {
|
|
362
|
+
let code = this.getSsoLoginCode();
|
|
363
|
+
if (code) {
|
|
364
|
+
this.customSsoLogin(code);
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (isCustomSsoLocalLogin(this.$route.query.redirect || this.searchParam.redirect)) {
|
|
369
|
+
this.login();
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// 主动退出若未跳到 logout_url 而回到登录页,尽量补跳;否则记下退出标记,避免循环
|
|
374
|
+
if (!getToken() && sessionStorage.getItem("ssoLogin") === "true") {
|
|
375
|
+
sessionStorage.removeItem("ssoLogin");
|
|
376
|
+
let logoutUrl = sessionStorage.getItem("ssoLogoutUrl");
|
|
377
|
+
if (logoutUrl) {
|
|
378
|
+
location.href = logoutUrl;
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
sessionStorage.setItem(CUSTOM_SSO_EXITED_KEY, "true");
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
let forced = this.hasCustomSsoFlag();
|
|
385
|
+
if (forced) {
|
|
386
|
+
sessionStorage.removeItem(CUSTOM_SSO_EXITED_KEY);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
if (sessionStorage.getItem(CUSTOM_SSO_EXITED_KEY) === "true") {
|
|
390
|
+
this.login();
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
let options = getCustomSsoOptions();
|
|
395
|
+
if (!options.autoJump && !forced) {
|
|
396
|
+
this.login();
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
this.showContent = false;
|
|
401
|
+
this.toCustomSsoLogin();
|
|
402
|
+
},
|
|
403
|
+
hasCustomSsoFlag() {
|
|
404
|
+
return this.searchParam.sso === "1" || this.$route.query.sso === "1";
|
|
405
|
+
},
|
|
406
|
+
toCustomSsoLogin() {
|
|
407
|
+
fetchCustomSsoConfig().then((objx) => {
|
|
408
|
+
let authorizeUrl = objx && objx.authorize_url;
|
|
409
|
+
if (authorizeUrl) {
|
|
410
|
+
location.href = authorizeUrl;
|
|
411
|
+
} else {
|
|
412
|
+
this.fallbackToLocalLogin();
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
},
|
|
416
|
+
fallbackToLocalLogin() {
|
|
417
|
+
this.showContent = true;
|
|
418
|
+
this.login();
|
|
419
|
+
},
|
|
420
|
+
/** 统一认证回调:用授权码换 token */
|
|
421
|
+
customSsoLogin(code) {
|
|
422
|
+
this.showContent = false;
|
|
423
|
+
let logoutReady = fetchCustomSsoConfig();
|
|
424
|
+
// 只删 Admin-Token:守卫在有 token 时会把 /login 弹回 /,授权码就兑不成了
|
|
425
|
+
removeToken();
|
|
426
|
+
this.$store.commit("user/SET_TOKEN", "");
|
|
427
|
+
let options = getCustomSsoOptions();
|
|
428
|
+
this.$http({
|
|
429
|
+
url: USER_PREFIX + "/auth/login",
|
|
430
|
+
method: "post",
|
|
431
|
+
useToken: false,
|
|
432
|
+
data: {
|
|
433
|
+
custom: "true",
|
|
434
|
+
[options.codeField]: code,
|
|
435
|
+
},
|
|
436
|
+
isLoading: true,
|
|
437
|
+
success: (res) => {
|
|
438
|
+
let token = res.objx;
|
|
439
|
+
this.$store.dispatch("user/addToken", { token }).then(() => {
|
|
440
|
+
sessionStorage.setItem("ssoLogin", "true");
|
|
441
|
+
sessionStorage.removeItem(CUSTOM_SSO_EXITED_KEY);
|
|
442
|
+
localStorage.removeItem("currentMenuId");
|
|
443
|
+
this.loading = false;
|
|
444
|
+
window.removeEventListener("keydown", this.keyDown, false);
|
|
445
|
+
const goHome = () => {
|
|
446
|
+
location.href = window.MAIN_WEB_PREFIX + "/index.html";
|
|
447
|
+
};
|
|
448
|
+
logoutReady.then(goHome).catch(goHome);
|
|
449
|
+
});
|
|
450
|
+
},
|
|
451
|
+
fail: () => {
|
|
452
|
+
sessionStorage.setItem(CUSTOM_SSO_EXITED_KEY, "true");
|
|
453
|
+
this.clearSsoCodeFromUrl();
|
|
454
|
+
this.fallbackToLocalLogin();
|
|
455
|
+
},
|
|
456
|
+
error: () => {
|
|
457
|
+
sessionStorage.setItem(CUSTOM_SSO_EXITED_KEY, "true");
|
|
458
|
+
this.clearSsoCodeFromUrl();
|
|
459
|
+
this.fallbackToLocalLogin();
|
|
460
|
+
},
|
|
461
|
+
});
|
|
462
|
+
},
|
|
463
|
+
getSsoLoginCode() {
|
|
464
|
+
let searchParam = getUrlParams(location.search);
|
|
465
|
+
return this.$route.query.code || searchParam.code;
|
|
466
|
+
},
|
|
467
|
+
/**
|
|
468
|
+
* 把授权码从地址栏剥掉。hash 路由下 location.search 不随路由跳转清除,
|
|
469
|
+
* 残留的 code 会在下次回到登录页时被当成新授权码反复兑换
|
|
470
|
+
*/
|
|
471
|
+
clearSsoCodeFromUrl() {
|
|
472
|
+
try {
|
|
473
|
+
if (/[?&]code=/.test(location.search)) {
|
|
474
|
+
let params = new URLSearchParams(location.search.slice(1));
|
|
475
|
+
params.delete("code");
|
|
476
|
+
let query = params.toString();
|
|
477
|
+
history.replaceState(
|
|
478
|
+
null,
|
|
479
|
+
"",
|
|
480
|
+
location.pathname + (query ? "?" + query : "") + location.hash
|
|
481
|
+
);
|
|
482
|
+
this.searchParam = getUrlParams(location.search);
|
|
483
|
+
}
|
|
484
|
+
if (this.$route.query.code) {
|
|
485
|
+
let query = { ...this.$route.query };
|
|
486
|
+
delete query.code;
|
|
487
|
+
this.$router
|
|
488
|
+
.replace({ path: this.$route.path, query })
|
|
489
|
+
.catch(() => {});
|
|
490
|
+
}
|
|
491
|
+
} catch (e) {
|
|
492
|
+
console.error(e);
|
|
493
|
+
}
|
|
494
|
+
},
|
|
340
495
|
bearSsoLogin() {
|
|
341
496
|
//小熊SSO返回判断--目前因为小熊单点返回ticket有问题要特殊处理
|
|
342
497
|
let urlParams = {};
|