Skip to content

Commit

Permalink
move idm method back to amplify method (#11898)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmrabian authored Oct 25, 2024
1 parent e3c74dc commit 882bc9d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 0 additions & 4 deletions services/ui-src/src/utils/auth/UserProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ const testComponent = (
);

// HELPERS
const mockReplace = jest.fn();

const originalLocationDescriptor: any = Object.getOwnPropertyDescriptor(
global,
"location"
Expand All @@ -61,7 +59,6 @@ const setWindowOrigin = (windowOrigin: string) => {
value: {
assign: jest.fn(),
origin: windowOrigin,
replace: mockReplace,
pathname: "/",
},
writable: true,
Expand Down Expand Up @@ -123,7 +120,6 @@ describe("<UserProvider />", () => {
});
expect(window.location.origin).toContain("mdctmcr.cms.gov");
expect(screen.getByTestId("testdiv")).toHaveTextContent("User Test");
expect(mockReplace).toHaveBeenCalled();
});
});

Expand Down
11 changes: 6 additions & 5 deletions services/ui-src/src/utils/auth/UserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -22,10 +26,7 @@ export const UserContext = createContext<UserContextShape>({
});

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) => {
Expand Down
1 change: 1 addition & 0 deletions services/ui-src/src/utils/testing/setupJest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jest.mock("aws-amplify/auth", () => ({
}),
}),
signOut: jest.fn().mockImplementation(() => Promise.resolve()),
signInWithRedirect: () => {},
}));

jest.mock("aws-amplify/utils", () => ({
Expand Down

0 comments on commit 882bc9d

Please sign in to comment.