Fix assume SAML required error redirect
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<d0c32c536987c19da427a6088151bd09>>
|
||||
* @generated SignedSource<<799dc16fa7e9b770dbaba857b2d887ef>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -25,7 +25,6 @@ export type AssumePageMutation$data = {
|
||||
} | {
|
||||
readonly __typename: "SAMLAuthenticationRequired";
|
||||
readonly reason: ReauthenticationReason;
|
||||
readonly redirectUrl: string;
|
||||
} | {
|
||||
// This will never be '%other', but we need some
|
||||
// value in case none of the concrete values match.
|
||||
@@ -46,13 +45,15 @@ var v0 = [
|
||||
"name": "input"
|
||||
}
|
||||
],
|
||||
v1 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "reason",
|
||||
"storageKey": null
|
||||
},
|
||||
v1 = [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "reason",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
v2 = [
|
||||
{
|
||||
"alias": null,
|
||||
@@ -85,24 +86,13 @@ v2 = [
|
||||
},
|
||||
{
|
||||
"kind": "InlineFragment",
|
||||
"selections": [
|
||||
(v1/*: any*/)
|
||||
],
|
||||
"selections": (v1/*: any*/),
|
||||
"type": "PasswordRequired",
|
||||
"abstractKey": null
|
||||
},
|
||||
{
|
||||
"kind": "InlineFragment",
|
||||
"selections": [
|
||||
(v1/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "redirectUrl",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"selections": (v1/*: any*/),
|
||||
"type": "SAMLAuthenticationRequired",
|
||||
"abstractKey": null
|
||||
}
|
||||
@@ -131,16 +121,16 @@ return {
|
||||
"selections": (v2/*: any*/)
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "073df17c6a8b470ae74d1d39243b3e30",
|
||||
"cacheID": "d8d9f257921f8f642821de2af7f22bcb",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "AssumePageMutation",
|
||||
"operationKind": "mutation",
|
||||
"text": "mutation AssumePageMutation(\n $input: AssumeOrganizationSessionInput!\n) {\n assumeOrganizationSession(input: $input) {\n result {\n __typename\n ... on PasswordRequired {\n reason\n }\n ... on SAMLAuthenticationRequired {\n reason\n redirectUrl\n }\n }\n }\n}\n"
|
||||
"text": "mutation AssumePageMutation(\n $input: AssumeOrganizationSessionInput!\n) {\n assumeOrganizationSession(input: $input) {\n result {\n __typename\n ... on PasswordRequired {\n reason\n }\n ... on SAMLAuthenticationRequired {\n reason\n }\n }\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "e6f39c43ccc7680cd72ad99c84a82780";
|
||||
(node as any).hash = "289d3534a87fa6cdb46384af573d5a57";
|
||||
|
||||
export default node;
|
||||
|
||||
108
apps/console/src/__generated__/iam/AssumePageQuery.graphql.ts
generated
Normal file
108
apps/console/src/__generated__/iam/AssumePageQuery.graphql.ts
generated
Normal file
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* @generated SignedSource<<480c5420502cccfbc55c32a61e1662c3>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ConcreteRequest } from 'relay-runtime';
|
||||
export type AssumePageQuery$variables = Record<PropertyKey, never>;
|
||||
export type AssumePageQuery$data = {
|
||||
readonly viewer: {
|
||||
readonly __typename: "Identity";
|
||||
readonly ssoLoginURL: string | null | undefined;
|
||||
};
|
||||
};
|
||||
export type AssumePageQuery = {
|
||||
response: AssumePageQuery$data;
|
||||
variables: AssumePageQuery$variables;
|
||||
};
|
||||
|
||||
const node: ConcreteRequest = (function(){
|
||||
var v0 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "__typename",
|
||||
"storageKey": null
|
||||
},
|
||||
v1 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "ssoLoginURL",
|
||||
"storageKey": null
|
||||
};
|
||||
return {
|
||||
"fragment": {
|
||||
"argumentDefinitions": [],
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "AssumePageQuery",
|
||||
"selections": [
|
||||
{
|
||||
"kind": "RequiredField",
|
||||
"field": {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "Identity",
|
||||
"kind": "LinkedField",
|
||||
"name": "viewer",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v0/*: any*/),
|
||||
(v1/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
"action": "THROW"
|
||||
}
|
||||
],
|
||||
"type": "Query",
|
||||
"abstractKey": null
|
||||
},
|
||||
"kind": "Request",
|
||||
"operation": {
|
||||
"argumentDefinitions": [],
|
||||
"kind": "Operation",
|
||||
"name": "AssumePageQuery",
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "Identity",
|
||||
"kind": "LinkedField",
|
||||
"name": "viewer",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v0/*: any*/),
|
||||
(v1/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "id",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "f922b5514212bff8d2da85b12f00c51e",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "AssumePageQuery",
|
||||
"operationKind": "query",
|
||||
"text": "query AssumePageQuery {\n viewer {\n __typename\n ssoLoginURL\n id\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "266ce6c5836b9e826718b07e03fcc36e";
|
||||
|
||||
export default node;
|
||||
@@ -1,13 +1,13 @@
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import { UnAuthenticatedError } from "@probo/relay";
|
||||
import { useEffect } from "react";
|
||||
import { useMutation } from "react-relay";
|
||||
import { type PreloadedQuery, useMutation, usePreloadedQuery } from "react-relay";
|
||||
import { useNavigate, useSearchParams } from "react-router";
|
||||
import { graphql } from "relay-runtime";
|
||||
|
||||
import type { AssumePageMutation } from "#/__generated__/iam/AssumePageMutation.graphql";
|
||||
import type { AssumePageQuery } from "#/__generated__/iam/AssumePageQuery.graphql";
|
||||
import { useOrganizationId } from "#/hooks/useOrganizationId";
|
||||
import { IAMRelayProvider } from "#/providers/IAMRelayProvider";
|
||||
|
||||
import AuthLayout from "../auth/AuthLayout";
|
||||
|
||||
@@ -23,19 +23,32 @@ const assumeMutation = graphql`
|
||||
}
|
||||
... on SAMLAuthenticationRequired {
|
||||
reason
|
||||
redirectUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
function AssumePageInner() {
|
||||
export const assumePageQuery = graphql`
|
||||
query AssumePageQuery {
|
||||
viewer @required(action: THROW) {
|
||||
__typename
|
||||
... on Identity {
|
||||
ssoLoginURL
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export function AssumePage(props: { queryRef: PreloadedQuery<AssumePageQuery> }) {
|
||||
const { queryRef } = props;
|
||||
|
||||
const organizationId = useOrganizationId();
|
||||
const navigate = useNavigate();
|
||||
const [searchParams] = useSearchParams();
|
||||
const { __ } = useTranslate();
|
||||
|
||||
const { viewer } = usePreloadedQuery<AssumePageQuery>(assumePageQuery, queryRef);
|
||||
const [assumeOrganizationSession] = useMutation<AssumePageMutation>(assumeMutation);
|
||||
|
||||
const continueUrlParam = searchParams.get("continue");
|
||||
@@ -80,7 +93,10 @@ function AssumePageInner() {
|
||||
void navigate({ pathname: "/auth/password-login", search: "?" + search.toString() });
|
||||
break;
|
||||
case "SAMLAuthenticationRequired":
|
||||
samlSSOLoginURL = new URL(result.redirectUrl);
|
||||
if (!viewer.ssoLoginURL) {
|
||||
throw new Error("missing SSO login URL for user email");
|
||||
}
|
||||
samlSSOLoginURL = new URL(viewer.ssoLoginURL);
|
||||
samlSSOLoginURL.search = "?" + searchParams.toString();
|
||||
|
||||
window.location.href = samlSSOLoginURL.toString();
|
||||
@@ -90,7 +106,7 @@ function AssumePageInner() {
|
||||
}
|
||||
},
|
||||
});
|
||||
}, [organizationId, navigate, assumeOrganizationSession, safeContinueUrl, searchParams]);
|
||||
}, [organizationId, navigate, assumeOrganizationSession, safeContinueUrl, searchParams, viewer.ssoLoginURL]);
|
||||
|
||||
return (
|
||||
<AuthLayout>
|
||||
@@ -105,11 +121,3 @@ function AssumePageInner() {
|
||||
</AuthLayout>
|
||||
);
|
||||
}
|
||||
|
||||
export default function AssumePage() {
|
||||
return (
|
||||
<IAMRelayProvider>
|
||||
<AssumePageInner />
|
||||
</IAMRelayProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { CenteredLayoutSkeleton } from "@probo/ui";
|
||||
import { useEffect } from "react";
|
||||
import { useQueryLoader } from "react-relay";
|
||||
|
||||
import type { AssumePageQuery } from "#/__generated__/iam/AssumePageQuery.graphql";
|
||||
import { IAMRelayProvider } from "#/providers/IAMRelayProvider";
|
||||
|
||||
import { AssumePage, assumePageQuery } from "./AssumePage";
|
||||
|
||||
function AssumePageQueryLoader() {
|
||||
const [queryRef, loadQuery] = useQueryLoader<AssumePageQuery>(assumePageQuery);
|
||||
|
||||
useEffect(() => {
|
||||
loadQuery({}, { fetchPolicy: "network-only" });
|
||||
}, [loadQuery]);
|
||||
|
||||
if (!queryRef) {
|
||||
return <CenteredLayoutSkeleton />;
|
||||
}
|
||||
|
||||
return <AssumePage queryRef={queryRef} />;
|
||||
}
|
||||
|
||||
export default function AssumePageLoader() {
|
||||
return (
|
||||
<IAMRelayProvider>
|
||||
<AssumePageQueryLoader />
|
||||
</IAMRelayProvider>
|
||||
);
|
||||
}
|
||||
@@ -125,7 +125,7 @@ const routes = [
|
||||
children: [
|
||||
{
|
||||
path: "assume",
|
||||
Component: lazy(() => import("./pages/iam/organizations/AssumePage")),
|
||||
Component: lazy(() => import("./pages/iam/organizations/AssumePageLoader")),
|
||||
},
|
||||
{
|
||||
path: "employee",
|
||||
|
||||
Reference in New Issue
Block a user