Skip to content

Commit

Permalink
[Backport 1.3] Fix for Tenancy info getting lost on re-login in SAML …
Browse files Browse the repository at this point in the history
…Authentication flow (#1058) (#1125)

* Fix for picking up tenancy from local storage in SAML AuthN flow

Signed-off-by: Aniketh Jain <[email protected]>
(cherry picked from commit 05649d6)
  • Loading branch information
expani authored Oct 5, 2022
1 parent 7679573 commit 64715fa
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
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

0 comments on commit 64715fa

Please sign in to comment.