Skip to content

feat(saml2): Redirect to SLO URL on the frontend #77036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 9, 2024

Conversation

leedongwei
Copy link
Member

@leedongwei leedongwei commented Sep 5, 2024

Related to #77033

If a SLO URL is returned by the logout API, we will redirect the browser to that URL. This is needed for Single-Logout to work, because we need the browser to clear the cookies that are attached to the IdP's domain.

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Sep 5, 2024
Copy link

codecov bot commented Sep 5, 2024

Bundle Report

Changes will increase total bundle size by 90.22kB (0.3%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
app-webpack-bundle-array-push 30.24MB 90.22kB ⬆️

Copy link

codecov bot commented Sep 5, 2024

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
7743 1 7742 0
View the top 1 failed tests by shortest run time
Sidebar has can logout Sidebar has can logout
Stack Traces | 0.16s run time
Error: expect(jest.fn()).toHaveBeenCalledWith(...expected)

Expected: "/auth/login/"

Number of calls: 0
    at Object.<anonymous> (.../components/sidebar/index.spec.tsx:130:36)

To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

await userEvent.click(screen.getByTestId('existing-member-link'));

expect(logout).toHaveBeenCalled();
await waitFor(() => expect(window.location.replace).toHaveBeenCalled());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this line because redirect was moved into logout function, which was mocked.

@@ -294,9 +291,7 @@ describe('AcceptOrganizationInvite', function () {

expect(screen.getByTestId('existing-member')).toBeInTheDocument();
await userEvent.click(screen.getByTestId('existing-member-link'));

expect(logout).toHaveBeenCalled();
await waitFor(() => expect(window.location.replace).toHaveBeenCalled());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this line because redirect was moved into logout function, which was mocked.

@leedongwei leedongwei marked this pull request as ready for review September 6, 2024 00:22
@leedongwei leedongwei requested a review from a team as a code owner September 6, 2024 00:22
@leedongwei leedongwei requested review from evanpurkhiser and a team and removed request for a team September 6, 2024 00:22
Copy link
Contributor

@saponifi3d saponifi3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

just a nit for the onClick={() = {}} functions in handlers -- that will be a little harder to debug if there's an issue (errors will just have anonymous) and the browsers js engine won't be able to create a hot cache of the anon functions for the react re-render cycles.

const data = await api.requestPromise('/auth/', {method: 'DELETE'});

// If there's a URL for SAML Single-logout, redirect back to IdP
window.location.assign(data?.sloUrl || redirectUrl);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use react-router here for consistency?

import { redirect } from "react-router-dom";

redirect(data?.sloUrl || redirectUrl))

const redirectURL = `${trimEnd(superuserUrl, '/')}${authLoginPath}`;
window.location.assign(redirectURL);
return;
nextUrl = `${trimEnd(superuserUrl, '/')}${nextUrl}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might be safer to use the URL constructor rather than build a string for the url. here's a little blog on how to use the URL constructor and the differences between the two approaches: https://www.builder.io/blog/new-url

Copy link
Contributor

@saponifi3d saponifi3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@leedongwei leedongwei merged commit d081ddd into master Sep 9, 2024
42 of 43 checks passed
@leedongwei leedongwei deleted the dlee/slo-redirect-fe branch September 9, 2024 21:02
c298lee pushed a commit that referenced this pull request Sep 10, 2024
Related to #77033

If a SLO URL is returned by the logout API, we will redirect the browser
to that URL. This is needed for Single-Logout to work, because we need
the browser to clear the cookies that are attached to the IdP's domain.
@github-actions github-actions bot locked and limited conversation to collaborators Sep 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants