Browse Source
Merge pull request #1135 from colinin/fix-qrcode-login
fix: Fixed multi-tenant QR code login
pull/1149/head
yx lin
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with
21 additions and
9 deletions
-
apps/vben5/apps/app-antd/src/store/auth.ts
-
apps/vben5/apps/app-antd/src/views/_core/authentication/qrcode-login.vue
-
apps/vben5/packages/@abp/account/src/api/useQrCodeLoginApi.ts
-
apps/vben5/packages/@abp/account/src/components/QrCodeLogin.vue
-
apps/vben5/packages/@abp/account/src/types/qrcode.ts
-
apps/vben5/packages/@abp/account/src/types/token.ts
-
apps/vben5/packages/@abp/identity/src/components/security-logs/SecurityLogTable.vue
|
|
|
@ -37,9 +37,10 @@ export const useAuthStore = defineStore('auth', () => { |
|
|
|
|
|
|
|
async function qrcodeLogin( |
|
|
|
key: string, |
|
|
|
tenantId?: string, |
|
|
|
onSuccess?: () => Promise<void> | void, |
|
|
|
) { |
|
|
|
const result = await qrcodeLoginApi(key); |
|
|
|
const result = await qrcodeLoginApi({ key, tenantId }); |
|
|
|
return await _loginSuccess(result, onSuccess); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -10,8 +10,8 @@ defineOptions({ name: 'QrCodeLogin' }); |
|
|
|
|
|
|
|
const authStore = useAuthStore(); |
|
|
|
|
|
|
|
async function onConfirm(key: string) { |
|
|
|
await authStore.qrcodeLogin(key); |
|
|
|
async function onConfirm(key: string, tenantId?: string) { |
|
|
|
await authStore.qrcodeLogin(key, tenantId); |
|
|
|
} |
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
|
|
@ -2,7 +2,7 @@ import type { |
|
|
|
GenerateQrCodeResult, |
|
|
|
QrCodeUserInfoResult, |
|
|
|
} from '../types/qrcode'; |
|
|
|
import type { OAuthTokenResult } from '../types/token'; |
|
|
|
import type { OAuthTokenResult, QrCodeTokenRequest } from '../types/token'; |
|
|
|
|
|
|
|
import { useAppConfig } from '@vben/hooks'; |
|
|
|
|
|
|
|
@ -37,7 +37,7 @@ export function useQrCodeLoginApi() { |
|
|
|
* @param key 二维码Key |
|
|
|
* @returns 用户token |
|
|
|
*/ |
|
|
|
async function loginApi(key: string) { |
|
|
|
async function loginApi(input: QrCodeTokenRequest) { |
|
|
|
const { audience, clientId, clientSecret } = useAppConfig( |
|
|
|
import.meta.env, |
|
|
|
import.meta.env.PROD, |
|
|
|
@ -47,8 +47,9 @@ export function useQrCodeLoginApi() { |
|
|
|
client_id: clientId, |
|
|
|
client_secret: clientSecret, |
|
|
|
grant_type: 'qr_code', |
|
|
|
qrcode_key: key, |
|
|
|
qrcode_key: input.key, |
|
|
|
scope: audience, |
|
|
|
tenant_id: input.tenantId, |
|
|
|
}, |
|
|
|
headers: { |
|
|
|
'Content-Type': 'application/x-www-form-urlencoded', |
|
|
|
|
|
|
|
@ -61,7 +61,7 @@ const props = withDefaults(defineProps<Props>(), { |
|
|
|
}); |
|
|
|
|
|
|
|
const emits = defineEmits<{ |
|
|
|
(event: 'confirm', key: string): void; |
|
|
|
(event: 'confirm', key: string, tenantId?: string): void; |
|
|
|
}>(); |
|
|
|
|
|
|
|
let interval: NodeJS.Timeout; |
|
|
|
@ -125,7 +125,7 @@ async function onCheckCode() { |
|
|
|
interval && clearInterval(interval); |
|
|
|
localStorage.removeItem('login_qrocde'); |
|
|
|
// 登录 |
|
|
|
emits('confirm', result.key); |
|
|
|
emits('confirm', result.key, result.tenantId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -20,6 +20,7 @@ interface QrCodeInfoResult { |
|
|
|
|
|
|
|
interface QrCodeUserInfoResult extends QrCodeInfoResult { |
|
|
|
picture?: string; |
|
|
|
tenantId?: string; |
|
|
|
userId?: string; |
|
|
|
userName?: string; |
|
|
|
} |
|
|
|
|
|
|
|
@ -14,6 +14,13 @@ interface PasswordTokenRequest extends TokenRequest { |
|
|
|
/** 用户名 */ |
|
|
|
userName: string; |
|
|
|
} |
|
|
|
/** 扫码登录授权请求数据模型 */ |
|
|
|
interface QrCodeTokenRequest { |
|
|
|
/** 二维码Key */ |
|
|
|
key: string; |
|
|
|
/** 租户Id */ |
|
|
|
tenantId?: string; |
|
|
|
} |
|
|
|
/** 用户密码授权请求数据模型 */ |
|
|
|
interface PasswordTokenRequestModel { |
|
|
|
/** 用户密码 */ |
|
|
|
@ -68,6 +75,7 @@ export type { |
|
|
|
OAuthTokenResult, |
|
|
|
PasswordTokenRequest, |
|
|
|
PasswordTokenRequestModel, |
|
|
|
QrCodeTokenRequest, |
|
|
|
TokenRequest, |
|
|
|
TokenResult, |
|
|
|
TwoFactorError, |
|
|
|
|
|
|
|
@ -1,4 +1,5 @@ |
|
|
|
<script setup lang="ts"> |
|
|
|
import type { SortOrder } from '@abp/core'; |
|
|
|
import type { VbenFormProps, VxeGridListeners, VxeGridProps } from '@abp/ui'; |
|
|
|
|
|
|
|
import type { SecurityLogDto } from '../../types/security-logs'; |
|
|
|
@ -8,7 +9,7 @@ import { defineAsyncComponent, h, ref, toValue } from 'vue'; |
|
|
|
import { useVbenDrawer } from '@vben/common-ui'; |
|
|
|
import { $t } from '@vben/locales'; |
|
|
|
|
|
|
|
import { formatToDateTime, type SortOrder } from '@abp/core'; |
|
|
|
import { formatToDateTime } from '@abp/core'; |
|
|
|
import { useVbenVxeGrid } from '@abp/ui'; |
|
|
|
import { DeleteOutlined, EditOutlined } from '@ant-design/icons-vue'; |
|
|
|
import { Button, message, Modal, Tag } from 'ant-design-vue'; |
|
|
|
|