diff --git a/client-app/core/composables/useAuth.ts b/client-app/core/composables/useAuth.ts index 7b12ec063..0a20dea7f 100644 --- a/client-app/core/composables/useAuth.ts +++ b/client-app/core/composables/useAuth.ts @@ -1,24 +1,11 @@ -import { useLocalStorage, createGlobalState } from "@vueuse/core"; +import type { AfterFetchContext } from "@vueuse/core"; +import { createGlobalState, useLocalStorage } from "@vueuse/core"; import { computed, ref } from "vue"; import { useFetch } from "@/core/api/common"; import { errorHandler, toServerError } from "@/core/api/common/utils"; import { globals } from "@/core/globals"; import { TabsType, unauthorizedErrorEvent, useBroadcast, userBeforeUnauthorizeEvent } from "@/shared/broadcast"; -import type { AfterFetchContext } from "@vueuse/core"; - -type IdentityErrorType = { - code?: string; - description?: string; -}; - -type ConnectTokenResponseType = { - expires_in?: number; - access_token?: string; - refresh_token?: string; - errors?: Array; - error: string; - token_type?: string; -}; +import type { ConnectTokenResponseType } from "../types"; function _useAuth() { const broadcast = useBroadcast(); @@ -107,13 +94,11 @@ function _useAuth() { } async function externalSignInCallback(): Promise { - const params = new URLSearchParams({ + getTokenParams.value = new URLSearchParams({ grant_type: "external_sign_in", scope: "offline_access", }); - getTokenParams.value = params; - await (getTokenRequest = getToken(true)); } @@ -184,6 +169,7 @@ function _useAuth() { setTokenType, setAccessToken, setExpiresAt, + setRefreshToken, }; } diff --git a/client-app/core/composables/useImpersonate.ts b/client-app/core/composables/useImpersonate.ts index 99376dce0..d1db5840b 100644 --- a/client-app/core/composables/useImpersonate.ts +++ b/client-app/core/composables/useImpersonate.ts @@ -9,7 +9,7 @@ import { useNotifications } from "@/shared/notification"; import type { ConnectTokenResponseType } from "../types"; export function _useImpersonate() { - const { setTokenType, setAccessToken, setExpiresAt } = useAuth(); + const { setTokenType, setAccessToken, setExpiresAt, setRefreshToken } = useAuth(); const broadcast = useBroadcast(); const status = ref(); const notifications = useNotifications(); @@ -23,6 +23,7 @@ export function _useImpersonate() { .post( new URLSearchParams({ grant_type: "impersonate", + scope: "offline_access", user_id: userId, }), "application/x-www-form-urlencoded", @@ -32,21 +33,28 @@ export function _useImpersonate() { if (!data.value || error.value) { status.value = "error"; } else { - const { access_token, token_type, expires_in } = data.value; + const { access_token, token_type, expires_in, refresh_token, error: tokenError, errors } = data.value; - setAccessToken(access_token); - setExpiresAt(expires_in); - setTokenType(token_type); + if (access_token && token_type && expires_in && refresh_token) { + setAccessToken(access_token); + setExpiresAt(expires_in); + setTokenType(token_type); + setRefreshToken(refresh_token); + status.value = "success"; + notifications.success({ text: t("pages.account.impersonate.success") }); - status.value = "success"; - notifications.success({ text: t("pages.account.impersonate.success") }); - - // reload all tabs to renew state - setTimeout(() => { - void broadcast.emit(reloadAndOpenMainPage, null, TabsType.ALL); - }, 1000); + // reload all tabs to renew state + setTimeout(() => { + void broadcast.emit(reloadAndOpenMainPage, null, TabsType.ALL); + }, 1000); + } else { + notifications.error({ text: t("pages.account.impersonate.error") }); + Logger.error(impersonate.name, tokenError, errors); + status.value = "error"; + } } } catch (e) { + notifications.error({ text: t("pages.account.impersonate.error") }); Logger.error(impersonate.name, e); status.value = "error"; } diff --git a/client-app/core/types/connect-token-response.ts b/client-app/core/types/connect-token-response.ts index b0e4a519e..26023f5ad 100644 --- a/client-app/core/types/connect-token-response.ts +++ b/client-app/core/types/connect-token-response.ts @@ -1,6 +1,13 @@ +type IdentityErrorType = { + code?: string; + description?: string; +}; + export type ConnectTokenResponseType = { - expires_in: number; - access_token: string; - token_type: string; + expires_in?: number; + access_token?: string; + refresh_token?: string; + errors?: Array; error?: string; + token_type?: string; }; diff --git a/locales/de.json b/locales/de.json index de5433e43..6a2f141f8 100644 --- a/locales/de.json +++ b/locales/de.json @@ -1105,7 +1105,7 @@ }, "impersonate": { "title": "Nachahmung", - "success": "Sie werden nachgeahmt", + "success": "Impersonation erfolgreich", "error": "Einige Probleme während der Nachahmung. Überprüfen Sie Ihre Berechtigungen" } }, diff --git a/locales/en.json b/locales/en.json index 76d9a600b..18a324a00 100644 --- a/locales/en.json +++ b/locales/en.json @@ -1105,7 +1105,7 @@ }, "impersonate": { "title": "Impersonation", - "success": "You are impersonated", + "success": "Impersonation succeeded", "error": "Some problems occurred during impersonation. Check your permissions" } }, diff --git a/locales/es.json b/locales/es.json index 8e2cf9949..a46fe7391 100644 --- a/locales/es.json +++ b/locales/es.json @@ -1105,7 +1105,7 @@ }, "impersonate": { "title": "Suplantación", - "success": "Estás suplantado", + "success": "Suplantación exitosa", "error": "Algunos problemas durante la suplantación. Verifica tus permisos" } }, diff --git a/locales/fr.json b/locales/fr.json index 5239b2fd2..647d0a04d 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -1105,7 +1105,7 @@ }, "impersonate": { "title": "Impersonation", - "success": "Vous êtes en train d'être imité", + "success": "Impersonation réussie", "error": "Des problèmes sont survenus lors de l'imitation. Vérifiez vos autorisations" } }, diff --git a/locales/it.json b/locales/it.json index 0e23e443a..e2cb93100 100644 --- a/locales/it.json +++ b/locales/it.json @@ -1105,7 +1105,7 @@ }, "impersonate": { "title": "Impersonificazione", - "success": "Sei impersonato", + "success": "Impersonificazione riuscita", "error": "Alcuni problemi durante l'impersonificazione. Controlla i tuoi permessi" } }, diff --git a/locales/ja.json b/locales/ja.json index bb2afbfe6..fc5010e88 100644 --- a/locales/ja.json +++ b/locales/ja.json @@ -1105,7 +1105,7 @@ }, "impersonate": { "title": "代理ログイン", - "success": "代理ログインしました", + "success": "代理ログイン成功", "error": "代理ログイン中に問題が発生しました。権限を確認してください" } }, diff --git a/locales/pl.json b/locales/pl.json index 89e676668..3111b8c1f 100644 --- a/locales/pl.json +++ b/locales/pl.json @@ -1105,7 +1105,7 @@ }, "impersonate": { "title": "Podrabianie", - "success": "Jesteś podrobiony", + "success": "Podrobienie zakończone", "error": "Wystąpiły problemy podczas podrabiania. Sprawdź swoje uprawnienia" } }, diff --git a/locales/pt.json b/locales/pt.json index bd6ee4755..dee49a9b1 100644 --- a/locales/pt.json +++ b/locales/pt.json @@ -1105,7 +1105,7 @@ }, "impersonate": { "title": "Impersonação", - "success": "Você está sendo personificado", + "success": "Impersonificação bem-sucedida", "error": "Alguns problemas durante a personificação. Verifique suas permissões" } }, diff --git a/locales/ru.json b/locales/ru.json index bfc870821..a97c77d42 100644 --- a/locales/ru.json +++ b/locales/ru.json @@ -1104,9 +1104,9 @@ "update_error_alert": "Произошла ошибка при обновлении профиля" }, "impersonate": { - "title": "Авторизация", - "success": "Вы авторизовались", - "error": "Возникли проблемы при авторизации. Проверьте ваши права доступа" + "title": "Имперсонализация", + "success": "Имперсонализация прошла успешно", + "error": "Возникли проблемы при имперсонализации. Проверьте ваши права доступа" } }, "company": { diff --git a/locales/zh.json b/locales/zh.json index 0ed3dee0d..8406195ca 100644 --- a/locales/zh.json +++ b/locales/zh.json @@ -1105,7 +1105,7 @@ }, "impersonate": { "title": "冒充", - "success": "您已被冒充", + "success": "冒充成功", "error": "冒充时出现一些问题。检查您的权限" } },