From 882bc9df8dc24ac078d4ba07874bd9b6ee1685be Mon Sep 17 00:00:00 2001
From: Garrett Rabian <57802560+gmrabian@users.noreply.github.com>
Date: Fri, 25 Oct 2024 13:13:15 -0400
Subject: [PATCH] move idm method back to amplify method (#11898)
---
services/ui-src/src/utils/auth/UserProvider.test.tsx | 4 ----
services/ui-src/src/utils/auth/UserProvider.tsx | 11 ++++++-----
services/ui-src/src/utils/testing/setupJest.tsx | 1 +
3 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/services/ui-src/src/utils/auth/UserProvider.test.tsx b/services/ui-src/src/utils/auth/UserProvider.test.tsx
index fb3b1cbef..a87117ae4 100644
--- a/services/ui-src/src/utils/auth/UserProvider.test.tsx
+++ b/services/ui-src/src/utils/auth/UserProvider.test.tsx
@@ -48,8 +48,6 @@ const testComponent = (
);
// HELPERS
-const mockReplace = jest.fn();
-
const originalLocationDescriptor: any = Object.getOwnPropertyDescriptor(
global,
"location"
@@ -61,7 +59,6 @@ const setWindowOrigin = (windowOrigin: string) => {
value: {
assign: jest.fn(),
origin: windowOrigin,
- replace: mockReplace,
pathname: "/",
},
writable: true,
@@ -123,7 +120,6 @@ describe("", () => {
});
expect(window.location.origin).toContain("mdctmcr.cms.gov");
expect(screen.getByTestId("testdiv")).toHaveTextContent("User Test");
- expect(mockReplace).toHaveBeenCalled();
});
});
diff --git a/services/ui-src/src/utils/auth/UserProvider.tsx b/services/ui-src/src/utils/auth/UserProvider.tsx
index 428255101..c1cf93267 100644
--- a/services/ui-src/src/utils/auth/UserProvider.tsx
+++ b/services/ui-src/src/utils/auth/UserProvider.tsx
@@ -6,7 +6,11 @@ import {
useMemo,
} from "react";
import { useLocation } from "react-router-dom";
-import { fetchAuthSession, signOut } from "aws-amplify/auth";
+import {
+ fetchAuthSession,
+ signInWithRedirect,
+ signOut,
+} from "aws-amplify/auth";
import config from "config";
// utils
import { initAuthManager, updateTimeout, getExpiration, useStore } from "utils";
@@ -22,10 +26,7 @@ export const UserContext = createContext({
});
const authenticateWithIDM = async () => {
- const cognitoHostedUrl = new URL(
- `https://${config.cognito.APP_CLIENT_DOMAIN}/oauth2/authorize?identity_provider=${config.cognito.COGNITO_IDP_NAME}&redirect_uri=${config.APPLICATION_ENDPOINT}&response_type=CODE&client_id=${config.cognito.APP_CLIENT_ID}&scope=email openid profile`
- );
- window.location.replace(cognitoHostedUrl);
+ await signInWithRedirect({ provider: { custom: "Okta" } });
};
export const UserProvider = ({ children }: Props) => {
diff --git a/services/ui-src/src/utils/testing/setupJest.tsx b/services/ui-src/src/utils/testing/setupJest.tsx
index e823ac3fb..2b22e2ad8 100644
--- a/services/ui-src/src/utils/testing/setupJest.tsx
+++ b/services/ui-src/src/utils/testing/setupJest.tsx
@@ -65,6 +65,7 @@ jest.mock("aws-amplify/auth", () => ({
}),
}),
signOut: jest.fn().mockImplementation(() => Promise.resolve()),
+ signInWithRedirect: () => {},
}));
jest.mock("aws-amplify/utils", () => ({