Login: fix consent for public client
This commit is contained in:
parent
def151fe66
commit
11b5de43c8
@ -27,8 +27,9 @@
|
|||||||
import React, { useEffect } from "react";
|
import React, { useEffect } from "react";
|
||||||
import { Loader } from "@docspace/shared/components/loader";
|
import { Loader } from "@docspace/shared/components/loader";
|
||||||
import Section from "@docspace/shared/components/section";
|
import Section from "@docspace/shared/components/section";
|
||||||
|
import { getCookie, deleteCookie } from "@docspace/shared/utils/cookie";
|
||||||
import { loginWithConfirmKey } from "@docspace/shared/api/user";
|
import { loginWithConfirmKey } from "@docspace/shared/api/user";
|
||||||
import { useSearchParams } from "react-router-dom";
|
import { useSearchParams, useLocation } from "react-router-dom";
|
||||||
import { combineUrl } from "@docspace/shared/utils/combineUrl";
|
import { combineUrl } from "@docspace/shared/utils/combineUrl";
|
||||||
import { toastr } from "@docspace/shared/components/toast";
|
import { toastr } from "@docspace/shared/components/toast";
|
||||||
import { frameCallEvent } from "@docspace/shared/utils/common";
|
import { frameCallEvent } from "@docspace/shared/utils/common";
|
||||||
@ -37,6 +38,7 @@ const Auth = (props) => {
|
|||||||
//console.log("Auth render");
|
//console.log("Auth render");
|
||||||
const { linkData } = props;
|
const { linkData } = props;
|
||||||
let [searchParams, setSearchParams] = useSearchParams();
|
let [searchParams, setSearchParams] = useSearchParams();
|
||||||
|
const location = useLocation();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loginWithConfirmKey({
|
loginWithConfirmKey({
|
||||||
ConfirmData: {
|
ConfirmData: {
|
||||||
@ -50,6 +52,22 @@ const Auth = (props) => {
|
|||||||
|
|
||||||
const url = searchParams.get("referenceUrl");
|
const url = searchParams.get("referenceUrl");
|
||||||
|
|
||||||
|
const redirectUrl = getCookie("x-redirect-authorization-uri");
|
||||||
|
|
||||||
|
deleteCookie("x-redirect-authorization-uri");
|
||||||
|
|
||||||
|
if (redirectUrl) {
|
||||||
|
window.location.replace(redirectUrl);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url && url.includes("oauth2")) {
|
||||||
|
const newUrl = location.search.split("referenceUrl=")[1];
|
||||||
|
|
||||||
|
window.location.replace(newUrl);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
try {
|
try {
|
||||||
new URL(url);
|
new URL(url);
|
||||||
|
@ -110,7 +110,6 @@ const Consent = ({ client, scopes, user }: IConsentProps) => {
|
|||||||
|
|
||||||
let clientState = "";
|
let clientState = "";
|
||||||
|
|
||||||
console.log(clientState);
|
|
||||||
const scope = client.scopes;
|
const scope = client.scopes;
|
||||||
|
|
||||||
const cookie = document.cookie.split(";");
|
const cookie = document.cookie.split(";");
|
||||||
@ -120,14 +119,6 @@ const Consent = ({ client, scopes, user }: IConsentProps) => {
|
|||||||
clientState = c.replace("client_state=", "").trim();
|
clientState = c.replace("client_state=", "").trim();
|
||||||
});
|
});
|
||||||
|
|
||||||
deleteCookie("client_state");
|
|
||||||
|
|
||||||
console.log(clientState, "run");
|
|
||||||
|
|
||||||
const state = await api.oauth.onOAuthLogin(clientId);
|
|
||||||
|
|
||||||
console.log(state);
|
|
||||||
|
|
||||||
await api.oauth.onOAuthSubmit(clientId, clientState, scope);
|
await api.oauth.onOAuthSubmit(clientId, clientState, scope);
|
||||||
|
|
||||||
setIsAllowRunning(false);
|
setIsAllowRunning(false);
|
||||||
@ -144,8 +135,6 @@ const Consent = ({ client, scopes, user }: IConsentProps) => {
|
|||||||
|
|
||||||
let clientState = "";
|
let clientState = "";
|
||||||
|
|
||||||
// await api.oauth.onOAuthLogin(clientId);
|
|
||||||
|
|
||||||
const cookie = document.cookie.split(";");
|
const cookie = document.cookie.split(";");
|
||||||
|
|
||||||
cookie.forEach((c) => {
|
cookie.forEach((c) => {
|
||||||
|
@ -49,9 +49,10 @@ import { toastr } from "@docspace/shared/components/toast";
|
|||||||
import { thirdPartyLogin } from "@docspace/shared/api/user";
|
import { thirdPartyLogin } from "@docspace/shared/api/user";
|
||||||
import { setWithCredentialsStatus } from "@docspace/shared/api/client";
|
import { setWithCredentialsStatus } from "@docspace/shared/api/client";
|
||||||
import { TValidate } from "@docspace/shared/components/email-input/EmailInput.types";
|
import { TValidate } from "@docspace/shared/components/email-input/EmailInput.types";
|
||||||
import api from "@docspace/shared/api";
|
|
||||||
import { RecaptchaType } from "@docspace/shared/enums";
|
import { RecaptchaType } from "@docspace/shared/enums";
|
||||||
import { getAvailablePortals } from "@docspace/shared/api/management";
|
import { getAvailablePortals } from "@docspace/shared/api/management";
|
||||||
|
import { getCookie } from "@docspace/shared/utils";
|
||||||
|
import { deleteCookie } from "@docspace/shared/utils/cookie";
|
||||||
|
|
||||||
import { LoginFormProps } from "@/types";
|
import { LoginFormProps } from "@/types";
|
||||||
import { generateOAuth2ReferenceURl, getEmailFromInvitation } from "@/utils";
|
import { generateOAuth2ReferenceURl, getEmailFromInvitation } from "@/utils";
|
||||||
@ -64,6 +65,7 @@ import LDAPContainer from "./sub-components/LDAPContainer";
|
|||||||
import { StyledCaptcha } from "./LoginForm.styled";
|
import { StyledCaptcha } from "./LoginForm.styled";
|
||||||
import { LoginDispatchContext, LoginValueContext } from "../Login";
|
import { LoginDispatchContext, LoginValueContext } from "../Login";
|
||||||
import OAuthClientInfo from "../ConsentInfo";
|
import OAuthClientInfo from "../ConsentInfo";
|
||||||
|
|
||||||
// import { gitAvailablePortals } from "@/utils/actions";
|
// import { gitAvailablePortals } from "@/utils/actions";
|
||||||
|
|
||||||
const LoginForm = ({
|
const LoginForm = ({
|
||||||
@ -263,11 +265,9 @@ const LoginForm = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (portals.length === 1) {
|
if (portals.length === 1) {
|
||||||
const referenceUrl = generateOAuth2ReferenceURl(client.clientId);
|
window.open(`${portals[0].portalLink}`, "_self");
|
||||||
window.open(
|
|
||||||
`${portals[0].portalLink}&referenceUrl=${referenceUrl}`,
|
return;
|
||||||
"_self",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
@ -284,10 +284,11 @@ const LoginForm = ({
|
|||||||
|
|
||||||
login(user, hash, pwd, session, captchaToken, currentCulture, reCaptchaType)
|
login(user, hash, pwd, session, captchaToken, currentCulture, reCaptchaType)
|
||||||
.then(async (res: string | object) => {
|
.then(async (res: string | object) => {
|
||||||
if (clientId) {
|
const redirectUrl = getCookie("x-redirect-authorization-uri");
|
||||||
await api.oauth.onOAuthLogin(clientId);
|
if (clientId && redirectUrl) {
|
||||||
|
deleteCookie("x-redirect-authorization-uri");
|
||||||
|
|
||||||
router.push(`/login/consent?clientId=${clientId}`);
|
window.location.replace(redirectUrl);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -9,5 +9,4 @@ export type TenantListProps = {
|
|||||||
export type ItemProps = {
|
export type ItemProps = {
|
||||||
portal: TPortal;
|
portal: TPortal;
|
||||||
baseDomain: string;
|
baseDomain: string;
|
||||||
clientId: string;
|
|
||||||
};
|
};
|
||||||
|
@ -23,12 +23,7 @@ const TenantList = ({ portals, clientId, baseDomain }: TenantListProps) => {
|
|||||||
</Text>
|
</Text>
|
||||||
<div className="items-list">
|
<div className="items-list">
|
||||||
{portals.map((item) => (
|
{portals.map((item) => (
|
||||||
<Item
|
<Item portal={item} key={item.portalName} baseDomain={baseDomain} />
|
||||||
portal={item}
|
|
||||||
key={item.portalName}
|
|
||||||
clientId={clientId}
|
|
||||||
baseDomain={baseDomain}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
|
@ -1,23 +1,26 @@
|
|||||||
/* eslint-disable @next/next/no-img-element */
|
/* eslint-disable @next/next/no-img-element */
|
||||||
|
|
||||||
import { Text } from "@docspace/shared/components/text";
|
import { Text } from "@docspace/shared/components/text";
|
||||||
|
import { IconButton } from "@docspace/shared/components/icon-button";
|
||||||
|
import { deleteCookie, getCookie } from "@docspace/shared/utils/cookie";
|
||||||
|
|
||||||
import ArrowRightSvrUrl from "PUBLIC_DIR/images/arrow.right.react.svg?url";
|
import ArrowRightSvrUrl from "PUBLIC_DIR/images/arrow.right.react.svg?url";
|
||||||
|
|
||||||
import { ItemProps } from "../TenantList.types";
|
import { ItemProps } from "../TenantList.types";
|
||||||
import { IconButton } from "@docspace/shared/components/icon-button";
|
|
||||||
import { generateOAuth2ReferenceURl } from "@/utils";
|
|
||||||
|
|
||||||
const Item = ({ clientId, portal, baseDomain }: ItemProps) => {
|
const Item = ({ portal, baseDomain }: ItemProps) => {
|
||||||
console.log(portal);
|
|
||||||
const name = portal.portalName.includes(baseDomain)
|
const name = portal.portalName.includes(baseDomain)
|
||||||
? portal.portalName
|
? portal.portalName
|
||||||
: `${portal.portalName}.${baseDomain}`;
|
: `${portal.portalName}.${baseDomain}`;
|
||||||
|
|
||||||
const onClick = () => {
|
const onClick = () => {
|
||||||
const referenceUrl = generateOAuth2ReferenceURl(clientId);
|
const redirectUrl = getCookie("x-redirect-authorization-uri")?.replace(
|
||||||
|
window.location.origin,
|
||||||
|
name,
|
||||||
|
);
|
||||||
|
deleteCookie("x-redirect-authorization-uri");
|
||||||
|
|
||||||
window.open(`${portal.portalLink}&referenceUrl=${referenceUrl}`, "_self");
|
window.open(`${portal.portalLink}&referenceUrl=${redirectUrl}`, "_self");
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -163,6 +163,9 @@ export const onOAuthSubmit = (
|
|||||||
url: `/oauth2/authorize`,
|
url: `/oauth2/authorize`,
|
||||||
data: formData,
|
data: formData,
|
||||||
withRedirect: true,
|
withRedirect: true,
|
||||||
|
headers: {
|
||||||
|
"X-Disable-Redirect": "true",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -177,5 +180,8 @@ export const onOAuthCancel = (clientId: string, clientState: string) => {
|
|||||||
url: `/oauth2/authorize`,
|
url: `/oauth2/authorize`,
|
||||||
data: formData,
|
data: formData,
|
||||||
withRedirect: true,
|
withRedirect: true,
|
||||||
|
headers: {
|
||||||
|
"X-Disable-Redirect": "true",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user