From 50bcf1d577707574667ccd3cfaeeb4ed536933e8 Mon Sep 17 00:00:00 2001 From: Timofey Boyko Date: Mon, 27 Nov 2023 17:45:04 +0300 Subject: [PATCH] Login:OAuth2: fix deny --- packages/common/api/oauth/index.ts | 16 +++++++++++- .../login/src/client/components/Login.tsx | 2 -- .../components/sub-components/Consent.tsx | 26 ++++++++++++++++--- .../components/sub-components/LoginForm.tsx | 1 - 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/packages/common/api/oauth/index.ts b/packages/common/api/oauth/index.ts index 0a8728387d..78bfe2b56c 100644 --- a/packages/common/api/oauth/index.ts +++ b/packages/common/api/oauth/index.ts @@ -28,7 +28,7 @@ export const getClient = async ( return { ...client, - websiteUrl: client.website_url, + websiteUrl: client?.website_url || "", }; } @@ -164,6 +164,20 @@ export const onOAuthSubmit = ( }); }; +export const onOAuthCancel = (clientId: string, clientState: string) => { + const formData = new FormData(); + + formData.append("client_id", clientId); + formData.append("state", clientState); + + return request({ + method: "post", + url: `/oauth2/authorize`, + data: formData, + withRedirect: true, + }); +}; + export const getConsentList = async (): Promise => { const clients: any = await request({ method: "get", diff --git a/packages/login/src/client/components/Login.tsx b/packages/login/src/client/components/Login.tsx index 53087779cf..2cacc70503 100644 --- a/packages/login/src/client/components/Login.tsx +++ b/packages/login/src/client/components/Login.tsx @@ -240,8 +240,6 @@ const Login: React.FC = ({ if (!mounted) return <>; if (isRestoringPortal) return <>; - console.log(portalSettings); - return ( { + const onDenyClick = async () => { + const clientId = oauth.clientId; + + let clientState = ""; + + setCookie("client_id", clientId); + + await api.oauth.onOAuthLogin(); + + const cookie = document.cookie.split(";"); + + cookie.forEach((c) => { + if (c.includes("client_state")) + clientState = c.replace("client_state=", "").trim(); + }); + deleteCookie("client_id"); deleteCookie("client_state"); - window.location.href = oauth.client.websiteUrl; + + await api.oauth.onOAuthCancel(clientId, clientState); }; const onChangeUserClick = async () => { diff --git a/packages/login/src/client/components/sub-components/LoginForm.tsx b/packages/login/src/client/components/sub-components/LoginForm.tsx index 4cfa2ee1ca..f3f6f5d480 100644 --- a/packages/login/src/client/components/sub-components/LoginForm.tsx +++ b/packages/login/src/client/components/sub-components/LoginForm.tsx @@ -221,7 +221,6 @@ const LoginForm: React.FC = ({ setIsLoading(true); - console.log(pass, hashSettings); const hash = createPasswordHash(pass, hashSettings); isDesktop && checkPwd();