Browse Source

fix: Fixed multi-tenant QR code login

pull/1135/head
colin 1 year ago
parent
commit
54a0dc137d
  1. 3
      apps/vben5/apps/app-antd/src/store/auth.ts
  2. 4
      apps/vben5/apps/app-antd/src/views/_core/authentication/qrcode-login.vue
  3. 7
      apps/vben5/packages/@abp/account/src/api/useQrCodeLoginApi.ts
  4. 4
      apps/vben5/packages/@abp/account/src/components/QrCodeLogin.vue
  5. 1
      apps/vben5/packages/@abp/account/src/types/qrcode.ts
  6. 8
      apps/vben5/packages/@abp/account/src/types/token.ts
  7. 3
      apps/vben5/packages/@abp/identity/src/components/security-logs/SecurityLogTable.vue

3
apps/vben5/apps/app-antd/src/store/auth.ts

@ -37,9 +37,10 @@ export const useAuthStore = defineStore('auth', () => {
async function qrcodeLogin( async function qrcodeLogin(
key: string, key: string,
tenantId?: string,
onSuccess?: () => Promise<void> | void, onSuccess?: () => Promise<void> | void,
) { ) {
const result = await qrcodeLoginApi(key); const result = await qrcodeLoginApi({ key, tenantId });
return await _loginSuccess(result, onSuccess); return await _loginSuccess(result, onSuccess);
} }

4
apps/vben5/apps/app-antd/src/views/_core/authentication/qrcode-login.vue

@ -10,8 +10,8 @@ defineOptions({ name: 'QrCodeLogin' });
const authStore = useAuthStore(); const authStore = useAuthStore();
async function onConfirm(key: string) { async function onConfirm(key: string, tenantId?: string) {
await authStore.qrcodeLogin(key); await authStore.qrcodeLogin(key, tenantId);
} }
</script> </script>

7
apps/vben5/packages/@abp/account/src/api/useQrCodeLoginApi.ts

@ -2,7 +2,7 @@ import type {
GenerateQrCodeResult, GenerateQrCodeResult,
QrCodeUserInfoResult, QrCodeUserInfoResult,
} from '../types/qrcode'; } from '../types/qrcode';
import type { OAuthTokenResult } from '../types/token'; import type { OAuthTokenResult, QrCodeTokenRequest } from '../types/token';
import { useAppConfig } from '@vben/hooks'; import { useAppConfig } from '@vben/hooks';
@ -37,7 +37,7 @@ export function useQrCodeLoginApi() {
* @param key Key * @param key Key
* @returns token * @returns token
*/ */
async function loginApi(key: string) { async function loginApi(input: QrCodeTokenRequest) {
const { audience, clientId, clientSecret } = useAppConfig( const { audience, clientId, clientSecret } = useAppConfig(
import.meta.env, import.meta.env,
import.meta.env.PROD, import.meta.env.PROD,
@ -47,8 +47,9 @@ export function useQrCodeLoginApi() {
client_id: clientId, client_id: clientId,
client_secret: clientSecret, client_secret: clientSecret,
grant_type: 'qr_code', grant_type: 'qr_code',
qrcode_key: key, qrcode_key: input.key,
scope: audience, scope: audience,
tenant_id: input.tenantId,
}, },
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',

4
apps/vben5/packages/@abp/account/src/components/QrCodeLogin.vue

@ -61,7 +61,7 @@ const props = withDefaults(defineProps<Props>(), {
}); });
const emits = defineEmits<{ const emits = defineEmits<{
(event: 'confirm', key: string): void; (event: 'confirm', key: string, tenantId?: string): void;
}>(); }>();
let interval: NodeJS.Timeout; let interval: NodeJS.Timeout;
@ -125,7 +125,7 @@ async function onCheckCode() {
interval && clearInterval(interval); interval && clearInterval(interval);
localStorage.removeItem('login_qrocde'); localStorage.removeItem('login_qrocde');
// //
emits('confirm', result.key); emits('confirm', result.key, result.tenantId);
} }
} }

1
apps/vben5/packages/@abp/account/src/types/qrcode.ts

@ -20,6 +20,7 @@ interface QrCodeInfoResult {
interface QrCodeUserInfoResult extends QrCodeInfoResult { interface QrCodeUserInfoResult extends QrCodeInfoResult {
picture?: string; picture?: string;
tenantId?: string;
userId?: string; userId?: string;
userName?: string; userName?: string;
} }

8
apps/vben5/packages/@abp/account/src/types/token.ts

@ -14,6 +14,13 @@ interface PasswordTokenRequest extends TokenRequest {
/** 用户名 */ /** 用户名 */
userName: string; userName: string;
} }
/** 扫码登录授权请求数据模型 */
interface QrCodeTokenRequest {
/** 二维码Key */
key: string;
/** 租户Id */
tenantId?: string;
}
/** 用户密码授权请求数据模型 */ /** 用户密码授权请求数据模型 */
interface PasswordTokenRequestModel { interface PasswordTokenRequestModel {
/** 用户密码 */ /** 用户密码 */
@ -68,6 +75,7 @@ export type {
OAuthTokenResult, OAuthTokenResult,
PasswordTokenRequest, PasswordTokenRequest,
PasswordTokenRequestModel, PasswordTokenRequestModel,
QrCodeTokenRequest,
TokenRequest, TokenRequest,
TokenResult, TokenResult,
TwoFactorError, TwoFactorError,

3
apps/vben5/packages/@abp/identity/src/components/security-logs/SecurityLogTable.vue

@ -1,4 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import type { SortOrder } from '@abp/core';
import type { VbenFormProps, VxeGridListeners, VxeGridProps } from '@abp/ui'; import type { VbenFormProps, VxeGridListeners, VxeGridProps } from '@abp/ui';
import type { SecurityLogDto } from '../../types/security-logs'; 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 { useVbenDrawer } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { formatToDateTime, type SortOrder } from '@abp/core'; import { formatToDateTime } from '@abp/core';
import { useVbenVxeGrid } from '@abp/ui'; import { useVbenVxeGrid } from '@abp/ui';
import { DeleteOutlined, EditOutlined } from '@ant-design/icons-vue'; import { DeleteOutlined, EditOutlined } from '@ant-design/icons-vue';
import { Button, message, Modal, Tag } from 'ant-design-vue'; import { Button, message, Modal, Tag } from 'ant-design-vue';

Loading…
Cancel
Save