From c206ab5b4a38f99bec4ee34d7b01bbabc83fa120 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期三, 19 六月 2024 14:29:44 +0800
Subject: [PATCH] update 优化 三方登录不同域名问题 采用新方案
---
src/views/login.vue | 4 ++--
src/layout/components/SocialCallback/index.vue | 6 ++++--
src/views/system/user/profile/thirdParty.vue | 4 ++--
src/api/system/social/auth.ts | 8 ++++++--
4 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/src/api/system/social/auth.ts b/src/api/system/social/auth.ts
index 17a46d3..69f0d7e 100644
--- a/src/api/system/social/auth.ts
+++ b/src/api/system/social/auth.ts
@@ -1,10 +1,14 @@
import request from '@/utils/request';
// 缁戝畾璐﹀彿
-export function authBinding(source: string) {
+export function authBinding(source: string, tenantId: string) {
return request({
url: '/auth/binding/' + source,
- method: 'get'
+ method: 'get',
+ params: {
+ tenantId: tenantId,
+ domain: window.location.host
+ }
});
}
diff --git a/src/layout/components/SocialCallback/index.vue b/src/layout/components/SocialCallback/index.vue
index 7edae44..1cfeca8 100644
--- a/src/layout/components/SocialCallback/index.vue
+++ b/src/layout/components/SocialCallback/index.vue
@@ -17,8 +17,9 @@
const code = route.query.code as string;
const state = route.query.state as string;
const source = route.query.source as string;
-const tenantId = route.query.tenantId as string ? route.query.tenantId as string : '000000';
-const domain = route.query.domain as string;
+const stateJson = JSON.parse(atob(state));
+const tenantId = stateJson.tenantId as string ? stateJson.tenantId as string : '000000';
+const domain = stateJson.domain as string;
const processResponse = async (res: any) => {
if (res.code !== 200) {
@@ -67,6 +68,7 @@
let urlFull = new URL(window.location.href);
urlFull.host = domain;
window.location.href = urlFull.toString();
+ return;
}
const data: LoginData = {
diff --git a/src/views/login.vue b/src/views/login.vue
index 02c7d77..ca2903f 100644
--- a/src/views/login.vue
+++ b/src/views/login.vue
@@ -191,10 +191,10 @@
* @param type
*/
const doSocialLogin = (type: string) => {
- authBinding(type).then((res: any) => {
+ authBinding(type, loginForm.value.tenantId).then((res: any) => {
if (res.code === HttpStatus.SUCCESS) {
// 鑾峰彇鎺堟潈鍦板潃璺宠浆
- window.location.href = res.data + '&tenantId=' + loginForm.value.tenantId + '&domain=' + window.location.host;
+ window.location.href = res.data;
} else {
ElMessage.error(res.msg);
}
diff --git a/src/views/system/user/profile/thirdParty.vue b/src/views/system/user/profile/thirdParty.vue
index ad090c4..957122a 100644
--- a/src/views/system/user/profile/thirdParty.vue
+++ b/src/views/system/user/profile/thirdParty.vue
@@ -84,9 +84,9 @@
};
const authUrl = (source: string) => {
- authBinding(source).then((res: any) => {
+ authBinding(source, useUserStore().tenantId).then((res: any) => {
if (res.code === 200) {
- window.location.href = res.data + '&tenantId=' + useUserStore().tenantId + '&domain=' + window.location.host;
+ window.location.href = res.data;
} else {
proxy?.$modal.msgError(res.msg);
}
--
Gitblit v1.9.3