Commit e24c2342 authored by qiyaxin's avatar qiyaxin

iam对接-登录

parent 277d8a7a
...@@ -169,7 +169,9 @@ function logout() { ...@@ -169,7 +169,9 @@ function logout() {
}) })
.then(() => { .then(() => {
userStore.logOut().then(() => { userStore.logOut().then(() => {
location.href = '/index' // 重定向到奇瑞统一身份认证平台的地址
const finalRedirectUrl = 'https://iamuat.mychery.com:5443/idp/oauth2/authorize?client_id=FACTS&redirect_uri=http://106.3.99.64:20073/login&response_type=code';
window.location.href = finalRedirectUrl;
}) })
}) })
.catch(() => {}) .catch(() => {})
......
...@@ -8,6 +8,7 @@ import { isRelogin } from '@/utils/request' ...@@ -8,6 +8,7 @@ import { isRelogin } from '@/utils/request'
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
import useSettingsStore from '@/store/modules/settings' import useSettingsStore from '@/store/modules/settings'
import usePermissionStore from '@/store/modules/permission' import usePermissionStore from '@/store/modules/permission'
import axios from 'axios';
NProgress.configure({ showSpinner: false }) NProgress.configure({ showSpinner: false })
...@@ -17,6 +18,11 @@ const isWhiteList = (path) => { ...@@ -17,6 +18,11 @@ const isWhiteList = (path) => {
return whiteList.some((pattern) => isPathMatch(pattern, path)) return whiteList.some((pattern) => isPathMatch(pattern, path))
} }
// 统一登录页面路由
const unifiedLoginRoute = '/login';
// 后端登录接口
const loginBySSOApi = '/auth/loginBySSO';
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
NProgress.start() NProgress.start()
if (getToken()) { if (getToken()) {
...@@ -63,9 +69,37 @@ router.beforeEach((to, from, next) => { ...@@ -63,9 +69,37 @@ router.beforeEach((to, from, next) => {
// 没有token // 没有token
if (isWhiteList(to.path)) { if (isWhiteList(to.path)) {
// 在免登录白名单,直接进入 // 在免登录白名单,直接进入
next() if (to.path === unifiedLoginRoute) {
// 从URL中截取code参数
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
if (code) {
// 请求后端/auth/loginBySSO接口
axios.post(loginBySSOApi, { ticket: code })
.then(response => {
if (response.data.success) {
// 登录成功,跳转到首页
next({ path: '/' });
} else {
ElMessage.error('登录失败,请重试');
next();
}
})
.catch(error => {
ElMessage.error('登录请求出错,请重试');
next();
});
} else {
next();
}
} else {
next()
}
} else { } else {
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页 // 跳转到IAM登录页面
const redirectUri = `http://106.3.99.64:20073${unifiedLoginRoute}`;
const iamLoginUrl = `https://iamuat.mychery.com:5443/idp/oauth2/authorize?client_id=FACTS&redirect_uri=${encodeURIComponent(redirectUri)}&response_type=code`;
window.location.href = iamLoginUrl;
NProgress.done() NProgress.done()
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment