Skip to content
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

[Backport 1.3] Tenancy getting Lost in SAML Authentication #1125

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions public/apps/account/log-out-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
import React from 'react';
import { EuiButtonEmpty } from '@elastic/eui';
import { HttpStart } from 'opensearch-dashboards/public';
import { logout } from './utils';
import { logout, samlLogout } from './utils';

export function LogoutButton(props: {
authType: string;
http: HttpStart;
divider: JSX.Element;
logoutUrl?: string;
}) {
if (props.authType === 'openid' || props.authType === 'saml') {
if (props.authType === 'openid') {
return (
<div>
{props.divider}
<EuiButtonEmpty
data-test-subj="log-out-1"
data-test-subj="log-out-2"
color="danger"
size="xs"
href={`${props.http.basePath.serverBasePath}/auth/logout`}
Expand All @@ -38,14 +38,28 @@ export function LogoutButton(props: {
</EuiButtonEmpty>
</div>
);
} else if (props.authType === 'saml') {
return (
<div>
{props.divider}
<EuiButtonEmpty
data-test-subj="log-out-1"
color="danger"
size="xs"
onClick={() => samlLogout(props.http)}
>
Log out
</EuiButtonEmpty>
</div>
);
} else if (props.authType === 'proxy') {
return <div />;
} else {
return (
<div>
{props.divider}
<EuiButtonEmpty
data-test-subj="log-out-2"
data-test-subj="log-out-3"
color="danger"
size="xs"
onClick={() => logout(props.http, props.logoutUrl)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`Account menu - Log out button renders renders when auth type is OpenId
<div>
<EuiButtonEmpty
color="danger"
data-test-subj="log-out-1"
data-test-subj="log-out-2"
href="/auth/logout"
size="xs"
>
Expand All @@ -20,7 +20,7 @@ exports[`Account menu - Log out button renders renders when auth type is SAML 1`
<EuiButtonEmpty
color="danger"
data-test-subj="log-out-1"
href="/auth/logout"
onClick={[Function]}
size="xs"
>
Log out
Expand All @@ -32,7 +32,7 @@ exports[`Account menu - Log out button renders renders when auth type is not Ope
<div>
<EuiButtonEmpty
color="danger"
data-test-subj="log-out-2"
data-test-subj="log-out-3"
onClick={[Function]}
size="xs"
>
Expand Down
2 changes: 1 addition & 1 deletion public/apps/account/test/log-out-button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('Account menu - Log out button', () => {
const component = shallow(
<LogoutButton authType="dummy" http={mockHttpStart} divider={mockDivider} />
);
component.find('[data-test-subj="log-out-2"]').simulate('click');
component.find('[data-test-subj="log-out-3"]').simulate('click');

expect(logout).toBeCalled();
});
Expand Down
6 changes: 6 additions & 0 deletions public/apps/account/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export async function logout(http: HttpStart, logoutUrl?: string): Promise<void>
logoutUrl || `${http.basePath.serverBasePath}/app/login?nextUrl=${nextUrl}`;
}

export async function samlLogout(http: HttpStart): Promise<void> {
// This will ensure tenancy is picked up from local storage in the next login.
setShouldShowTenantPopup(null);
window.location.href = `${http.basePath.serverBasePath}${API_AUTH_LOGOUT}`;
}

export async function updateNewPassword(
http: HttpStart,
newPassword: string,
Expand Down