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
parent
commit
a3f0ec9e5b
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  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(
key: string,
tenantId?: string,
onSuccess?: () => Promise<void> | void,
) {
const result = await qrcodeLoginApi(key);
const result = await qrcodeLoginApi({ key, tenantId });
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();
async function onConfirm(key: string) {
await authStore.qrcodeLogin(key);
async function onConfirm(key: string, tenantId?: string) {
await authStore.qrcodeLogin(key, tenantId);
}
</script>

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

@ -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',

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

@ -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);
}
}

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

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

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

@ -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,

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

@ -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';

Loading…
Cancel
Save