Client: fix after merge develop

This commit is contained in:
Timofey Boyko 2024-01-18 16:03:01 +03:00
parent 16ada7a735
commit f129e8f1dc
7 changed files with 87 additions and 39 deletions

View File

@ -12,7 +12,7 @@ import {
getScopeList,
getConsentList,
revokeUserClient,
} from "@docspace/common/api/oauth";
} from "@docspace/shared/api/oauth";
import {
IClientListProps,
@ -20,10 +20,9 @@ import {
IClientReqDTO,
INoAuthClientProps,
IScope,
} from "@docspace/common/utils/oauth/interfaces";
} from "@docspace/shared/utils/oauth/interfaces";
//@ts-ignore
import toastr from "@docspace/components/toast/toastr";
import { toastr } from "@docspace/shared/components/toast";
import SettingsIcon from "PUBLIC_DIR/images/catalog.settings.react.svg?url";
import DeleteIcon from "PUBLIC_DIR/images/delete.react.svg?url";
@ -33,8 +32,9 @@ import PencilReactSvgUrl from "PUBLIC_DIR/images/pencil.react.svg?url";
import CodeReactSvgUrl from "PUBLIC_DIR/images/code.react.svg?url";
import ExternalLinkReactSvgUrl from "PUBLIC_DIR/images/external.link.react.svg?url";
import OauthRevokeSvgUrl from "PUBLIC_DIR/images/oauth.revoke.svg?url";
import { transformToClientProps } from "@docspace/common/utils/oauth";
import { AuthenticationMethod } from "@docspace/common/utils/oauth/enums";
import { transformToClientProps } from "@docspace/shared/utils/oauth";
import { AuthenticationMethod } from "@docspace/shared/enums";
import { TData } from "@docspace/shared/components/toast/Toast.type";
const PAGE_LIMIT = 100;
@ -260,8 +260,9 @@ class OAuthStore implements OAuthStoreProps {
const client = await getClient(clientId);
return client;
} catch (e) {
toastr.error(e);
} catch (e: unknown) {
const err = e as TData;
toastr.error(err);
console.log(e);
}
};
@ -284,7 +285,8 @@ class OAuthStore implements OAuthStoreProps {
});
this.setClientsIsLoading(false);
} catch (e) {
toastr.error(e);
const err = e as TData;
toastr.error(err);
console.log(e);
}
};
@ -297,7 +299,8 @@ class OAuthStore implements OAuthStoreProps {
this.consents = [...consentList];
});
} catch (e) {
toastr.error(e);
const err = e as TData;
toastr.error(err);
console.log(e);
}
};
@ -343,7 +346,8 @@ class OAuthStore implements OAuthStoreProps {
];
});
} catch (e) {
toastr.error(e);
const err = e as TData;
toastr.error(err);
console.log(e);
}
};
@ -375,7 +379,8 @@ class OAuthStore implements OAuthStoreProps {
});
}
} catch (e) {
toastr.error(e);
const err = e as TData;
toastr.error(err);
console.log(e);
}
};
@ -392,7 +397,8 @@ class OAuthStore implements OAuthStoreProps {
});
}
} catch (e) {
toastr.error(e);
const err = e as TData;
toastr.error(err);
console.log(e);
}
};
@ -405,7 +411,8 @@ class OAuthStore implements OAuthStoreProps {
return client_secret;
} catch (e) {
toastr.error(e);
const err = e as TData;
toastr.error(err);
console.log(e);
}
};
@ -429,7 +436,8 @@ class OAuthStore implements OAuthStoreProps {
this.setActiveClient("");
} catch (e) {
toastr.error(e);
const err = e as TData;
toastr.error(err);
console.log(e);
}
};
@ -440,7 +448,8 @@ class OAuthStore implements OAuthStoreProps {
return scope;
} catch (e) {
toastr.error(e);
const err = e as TData;
toastr.error(err);
console.log(e);
return {} as IScope;
@ -453,7 +462,8 @@ class OAuthStore implements OAuthStoreProps {
this.scopes = scopes;
} catch (e) {
toastr.error(e);
const err = e as TData;
toastr.error(err);
console.log(e);
}
};
@ -477,7 +487,8 @@ class OAuthStore implements OAuthStoreProps {
this.setActiveClient("");
} catch (e) {
toastr.error(e);
const err = e as TData;
toastr.error(err);
console.log(e);
}
};
@ -602,7 +613,8 @@ class OAuthStore implements OAuthStoreProps {
this.setActiveClient("");
this.setSelection("");
} catch (e) {
toastr.error(e);
const err = e as TData;
toastr.error(err);
}
} else {
this.setActiveClient(clientId);

View File

@ -90,9 +90,7 @@ const Consent = ({
let clientState = "";
const scope = oauth.client.scopes;
setCookie("client_id", clientId);
await api.oauth.onOAuthLogin();
await api.oauth.onOAuthLogin(clientId);
const cookie = document.cookie.split(";");
@ -101,7 +99,6 @@ const Consent = ({
clientState = c.replace("client_state=", "").trim();
});
deleteCookie("client_id");
deleteCookie("client_state");
await api.oauth.onOAuthSubmit(clientId, clientState, scope);
@ -112,9 +109,7 @@ const Consent = ({
let clientState = "";
setCookie("client_id", clientId);
await api.oauth.onOAuthLogin();
await api.oauth.onOAuthLogin(clientId);
const cookie = document.cookie.split(";");
@ -123,7 +118,6 @@ const Consent = ({
clientState = c.replace("client_state=", "").trim();
});
deleteCookie("client_id");
deleteCookie("client_state");
await api.oauth.onOAuthCancel(clientId, clientState);

View File

@ -1,5 +1,5 @@
{
"date": "2024118_10460",
"date": "2024118_14311",
"checksums": {
"api.js": "cc6df9a4cf6c0ce8bed75e8cd3890b9a",
"api.poly.js": "586ce6831fa68f6bc33486e2cebc856e",

View File

@ -10,6 +10,7 @@ import {
IScope,
INoAuthClientProps,
IClientReqDTO,
IGetConsentList,
} from "../../utils/oauth/interfaces";
export const getClient = async (
@ -123,12 +124,12 @@ export const getScopeList = async (): Promise<IScope[]> => {
return scopeList;
};
export const onOAuthLogin = () => {
export const onOAuthLogin = (clientId: string) => {
const formData = new FormData();
return request({
method: "post",
url: `/oauth2/login`,
url: `/oauth2/login?client_id=${clientId}`,
data: formData,
withRedirect: true,
headers: {
@ -180,18 +181,23 @@ export const onOAuthCancel = (clientId: string, clientState: string) => {
};
export const getConsentList = async (): Promise<IClientProps[]> => {
const clients = await request({
const clients = (await request({
method: "get",
url: "/clients/consents",
});
})) as IGetConsentList[];
const consents: IClientProps[] = [];
clients.forEach((item) => {
const client = transformToClientProps(item.client);
clients.forEach(({ client, invalidated, modified_at }: IGetConsentList) => {
const consentClient: IClientResDTO = {
...client,
client_secret: "",
logout_redirect_uri: "",
};
if (!item.invalidated)
consents.push({ ...client, modifiedOn: item.modified_at });
const cl = transformToClientProps(consentClient);
if (!invalidated) consents.push({ ...cl, modifiedOn: modified_at });
});
return consents;

View File

@ -3,7 +3,6 @@
import axios, { AxiosInstance, AxiosRequestConfig } from "axios";
import { combineUrl } from "@docspace/shared/utils/combineUrl";
import defaultConfig from "PUBLIC_DIR/scripts/config.json";
import { setCookie } from "./cookie";
const { api: apiConf, proxy: proxyConf } = defaultConfig;
const { origin: apiOrigin, prefix: apiPrefix, timeout: apiTimeout } = apiConf;
@ -66,7 +65,7 @@ class AxiosClient {
"Access-Control-Allow-Credentials": "true",
};
}
setCookie("x-docspace-address", origin, {}, true);
const shareIndex = window.location.pathname.indexOf("share");
const sharedIndex = window.location.pathname.indexOf("shared");
@ -180,7 +179,11 @@ class AxiosClient {
if (!response || !response.data || response.isAxiosError) return null;
if (response.data && "total" in response.data)
if (
response.data &&
typeof response.data !== "string" &&
"total" in response.data
)
return {
total: response.data.total ? +response.data.total : 0,
items: response.data.response,

View File

@ -118,3 +118,36 @@ export interface ISubmitReqDTO {
state: string;
scopes: string[];
}
export type TConsentClient = {
authentication_methods: AuthenticationMethod[];
client_id: string;
created_by: string;
created_on: Date;
description: string;
enabled: boolean;
invalidated: boolean;
tenant: number;
tenant_url: string;
terms_url: string;
website_url: string;
modified_by: string;
modified_on: Date;
name: string;
policy_url: string;
logo: string;
links: string[];
logout_redirect_uris: string[];
redirect_uris: string[];
scopes: string[];
allowed_origins: string[];
};
export interface IGetConsentList {
client: TConsentClient;
invalidated: boolean;
modified_at: Date;
principal_name: string;
registered_client_id: string;
scopes: string;
}