-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add SSO option during PerSessionMFA in the web #47876
Changes from all commits
fae8ea8
baa1545
6187e65
eaf3b74
e43065e
acb29f4
5e7a02e
3a52927
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/** | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, screen, fireEvent } from 'design/utils/testing'; | ||
|
||
import { makeDefaultMfaState, MfaState } from 'teleport/lib/useMfa'; | ||
import { SSOChallenge } from 'teleport/services/auth'; | ||
|
||
import AuthnDialog from './AuthnDialog'; | ||
|
||
const mockSsoChallenge: SSOChallenge = { | ||
redirectUrl: 'url', | ||
requestId: '123', | ||
device: { | ||
displayName: 'Okta', | ||
connectorId: '123', | ||
connectorType: 'saml', | ||
}, | ||
channelId: '123', | ||
}; | ||
|
||
function makeMockState(partial: Partial<MfaState>): MfaState { | ||
const mfa = makeDefaultMfaState(); | ||
return { | ||
...mfa, | ||
...partial, | ||
}; | ||
} | ||
|
||
describe('AuthnDialog', () => { | ||
const mockOnCancel = jest.fn(); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('renders the dialog with basic content', () => { | ||
const mfa = makeMockState({ ssoChallenge: mockSsoChallenge }); | ||
render(<AuthnDialog mfa={mfa} onCancel={mockOnCancel} />); | ||
|
||
expect( | ||
screen.getByText('Re-authenticate in the Browser') | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.getByText( | ||
'To continue, you must verify your identity by re-authenticating:' | ||
) | ||
).toBeInTheDocument(); | ||
expect(screen.getByText('Okta')).toBeInTheDocument(); | ||
expect(screen.getByTestId('close-dialog')).toBeInTheDocument(); | ||
}); | ||
|
||
test('displays error text when provided', () => { | ||
const errorText = 'Authentication failed'; | ||
const mfa = makeMockState({ errorText }); | ||
render(<AuthnDialog mfa={mfa} onCancel={mockOnCancel} />); | ||
|
||
expect(screen.getByTestId('danger-alert')).toBeInTheDocument(); | ||
expect(screen.getByText(errorText)).toBeInTheDocument(); | ||
}); | ||
|
||
test('sso button renders with callback', async () => { | ||
const mfa = makeMockState({ | ||
ssoChallenge: mockSsoChallenge, | ||
onSsoAuthenticate: jest.fn(), | ||
}); | ||
render(<AuthnDialog mfa={mfa} onCancel={mockOnCancel} />); | ||
const ssoButton = screen.getByText('Okta'); | ||
fireEvent.click(ssoButton); | ||
expect(mfa.onSsoAuthenticate).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('webauthn button renders with callback', async () => { | ||
const mfa = makeMockState({ | ||
webauthnPublicKey: { challenge: new ArrayBuffer(0) }, | ||
onWebauthnAuthenticate: jest.fn(), | ||
}); | ||
render(<AuthnDialog mfa={mfa} onCancel={mockOnCancel} />); | ||
const webauthn = screen.getByText('Passkey or MFA Device'); | ||
fireEvent.click(webauthn); | ||
expect(mfa.onWebauthnAuthenticate).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,46 +17,64 @@ | |
*/ | ||
|
||
import React from 'react'; | ||
import Dialog, { | ||
DialogHeader, | ||
DialogTitle, | ||
DialogContent, | ||
} from 'design/Dialog'; | ||
import Dialog, { DialogContent } from 'design/Dialog'; | ||
import { Danger } from 'design/Alert'; | ||
import { Text, ButtonPrimary, ButtonSecondary, Flex } from 'design'; | ||
import { FingerprintSimple, Cross } from 'design/Icon'; | ||
|
||
import { Text, ButtonSecondary, Flex, ButtonIcon, H2 } from 'design'; | ||
|
||
import { guessProviderType } from 'shared/components/ButtonSso'; | ||
import { SSOIcon } from 'shared/components/ButtonSso/ButtonSso'; | ||
|
||
import { MfaState } from 'teleport/lib/useMfa'; | ||
|
||
export default function AuthnDialog({ mfa, onCancel }: Props) { | ||
return ( | ||
<Dialog dialogCss={() => ({ width: '500px' })} open={true}> | ||
<DialogHeader style={{ flexDirection: 'column' }}> | ||
<DialogTitle textAlign="center"> | ||
Multi-factor authentication | ||
</DialogTitle> | ||
</DialogHeader> | ||
<DialogContent mb={6}> | ||
<Dialog dialogCss={() => ({ width: '400px' })} open={true}> | ||
<Flex justifyContent="space-between" alignItems="center" mb={4}> | ||
<H2>Re-authenticate in the Browser</H2> | ||
<ButtonIcon data-testid="close-dialog" onClick={onCancel}> | ||
<Cross color="text.slightlyMuted" /> | ||
</ButtonIcon> | ||
</Flex> | ||
<DialogContent mb={5}> | ||
{mfa.errorText && ( | ||
<Danger mt={2} width="100%"> | ||
<Danger data-testid="danger-alert" mt={2} width="100%"> | ||
{mfa.errorText} | ||
</Danger> | ||
)} | ||
<Text textAlign="center"> | ||
Re-enter your multi-factor authentication in the browser to continue. | ||
<Text textAlign="center" color="text.slightlyMuted"> | ||
To continue, you must verify your identity by re-authenticating: | ||
</Text> | ||
</DialogContent> | ||
<Flex textAlign="center" justifyContent="center"> | ||
{/* TODO (avatus) this will eventually be conditionally rendered based on what | ||
type of challenges exist. For now, its only webauthn. */} | ||
<ButtonPrimary | ||
onClick={mfa.onWebauthnAuthenticate} | ||
autoFocus | ||
mr={3} | ||
width="130px" | ||
> | ||
{mfa.errorText ? 'Retry' : 'OK'} | ||
</ButtonPrimary> | ||
<ButtonSecondary onClick={onCancel}>Cancel</ButtonSecondary> | ||
<Flex textAlign="center" width="100%" flexDirection="column" gap={2}> | ||
{mfa.ssoChallenge && ( | ||
<ButtonSecondary | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why can't we just reuse the entire There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forget what issue I had using the entire button SSO component but I'll revisit and try again, thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh thats right, because the rest of the buttons around this dialog aren't sso. There is only 1 SSO challenge being retreives, and/or a webauthn challenge. So its either use ButtonSso for the single sso option and also for two non-sso buttons (webauthn and totp. totp isnt in yet tho) or just remake a button in here for this dialog to match. And I'd rather these 3 buttons in this dialog all use the same button instead of ButtonSso for one and a "copy" of its styles for the non sso buttons |
||
size="extra-large" | ||
onClick={mfa.onSsoAuthenticate} | ||
gap={2} | ||
block | ||
> | ||
<SSOIcon | ||
type={guessProviderType( | ||
mfa.ssoChallenge.device.displayName, | ||
mfa.ssoChallenge.device.connectorType | ||
)} | ||
/> | ||
{mfa.ssoChallenge.device.displayName} | ||
</ButtonSecondary> | ||
)} | ||
{mfa.webauthnPublicKey && ( | ||
<ButtonSecondary | ||
size="extra-large" | ||
onClick={mfa.onWebauthnAuthenticate} | ||
gap={2} | ||
block | ||
> | ||
<FingerprintSimple /> | ||
Passkey or MFA Device | ||
</ButtonSecondary> | ||
)} | ||
</Flex> | ||
</Dialog> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,13 +18,25 @@ | |
|
||
import { EventEmitter } from 'events'; | ||
|
||
import { WebauthnAssertionResponse } from 'teleport/services/auth'; | ||
import { | ||
MfaChallengeResponse, | ||
WebauthnAssertionResponse, | ||
} from 'teleport/services/auth'; | ||
|
||
class EventEmitterMfaSender extends EventEmitter { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this class extend There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class gets extended by tty (and desktop client), which emits many things. This prior work seems to be more for typing (perhaps virtual/abstract methods instead but I'll check out the impact of that) |
||
constructor() { | ||
super(); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
sendChallengeResponse(data: MfaChallengeResponse) { | ||
throw new Error('Not implemented'); | ||
} | ||
|
||
// TODO (avatus) DELETE IN 18 | ||
/** | ||
* @deprecated Use sendChallengeResponse instead. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
sendWebAuthn(data: WebauthnAssertionResponse) { | ||
throw new Error('Not implemented'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, as a side note (not to be addressed in this particular PR): perhaps we should use an
alert
ARIA role for warning and danger boxes. This would both help making these more accessible, and would help in writing tests. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that'd probably be more helpful