-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Open authorize device popup with deeplink (#40802)
- Loading branch information
Showing
9 changed files
with
238 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,26 +213,6 @@ describe('parseDeepLink followed by makeDeepLinkWithSafeInput gives the same res | |
'teleport://cluster.example.com/connect_my_computer', | ||
'teleport://[email protected]/connect_my_computer', | ||
'teleport://alice.bobson%[email protected]:1337/connect_my_computer', | ||
]; | ||
|
||
test.each(inputs)('%s', input => { | ||
const parseResult = parseDeepLink(input); | ||
expect(parseResult).toMatchObject({ status: 'success' }); | ||
const { url } = parseResult as DeepLinkParseResultSuccess; | ||
const deepLink = makeDeepLinkWithSafeInput({ | ||
proxyHost: url.host, | ||
path: url.pathname, | ||
username: url.username, | ||
searchParams: {}, | ||
}); | ||
expect(deepLink).toEqual(input); | ||
}); | ||
}); | ||
|
||
describe('"parseDeepLink followed by makeDeepLinkWithSafeInput gives the same result"', () => { | ||
const inputs: string[] = [ | ||
'teleport://cluster.example.com/connect_my_computer', | ||
'teleport://[email protected]/connect_my_computer', | ||
'teleport://[email protected]/authenticate_web_device?id=123&token=234', | ||
]; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...s/teleterm/src/ui/ModalsHost/modals/AuthenticateWebDevice/AuthenticateWebDevice.story.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Teleport | ||
* Copyright (C) 2023 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 { makeRootCluster } from 'teleterm/services/tshd/testHelpers'; | ||
import { MockAppContextProvider } from 'teleterm/ui/fixtures/MockAppContextProvider'; | ||
|
||
import { AuthenticateWebDevice } from './AuthenticateWebDevice'; | ||
|
||
export default { | ||
title: 'Teleterm/ModalsHost/AuthenticateWebDevice', | ||
}; | ||
|
||
export const Dialog = () => ( | ||
<MockAppContextProvider> | ||
<AuthenticateWebDevice | ||
rootClusterUri={makeRootCluster().uri} | ||
onClose={() => {}} | ||
onAuthorize={async () => {}} | ||
/> | ||
</MockAppContextProvider> | ||
); |
76 changes: 76 additions & 0 deletions
76
...ackages/teleterm/src/ui/ModalsHost/modals/AuthenticateWebDevice/AuthenticateWebDevice.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* 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 Alert from 'design/Alert'; | ||
import { ButtonPrimary, ButtonSecondary, Text } from 'design'; | ||
import Dialog, { DialogContent } from 'design/Dialog'; | ||
import Flex from 'design/Flex'; | ||
import { useAsync } from 'shared/hooks/useAsync'; | ||
|
||
import { useAppContext } from 'teleterm/ui/appContextProvider'; | ||
import { RootClusterUri, routing } from 'teleterm/ui/uri'; | ||
|
||
type Props = { | ||
rootClusterUri: RootClusterUri; | ||
onClose(): void; | ||
onAuthorize(): Promise<void>; | ||
}; | ||
|
||
export const AuthenticateWebDevice = ({ | ||
onAuthorize, | ||
onClose, | ||
rootClusterUri, | ||
}: Props) => { | ||
const [attempt, run] = useAsync(async () => { | ||
await onAuthorize(); | ||
onClose(); | ||
}); | ||
const { clustersService } = useAppContext(); | ||
const clusterName = | ||
clustersService.findCluster(rootClusterUri)?.name || | ||
routing.parseClusterName(rootClusterUri); | ||
|
||
return ( | ||
<Dialog open={true}> | ||
{/* 360px was used as a way to do our best to get clusterName as the first item on the second line */} | ||
<DialogContent maxWidth="360px"> | ||
<Text> | ||
Would you like to launch an authorized web session for{' '} | ||
<b>{clusterName}</b>? | ||
</Text> | ||
</DialogContent> | ||
{attempt.status === 'error' && <Alert>{attempt.statusText}</Alert>} | ||
<Flex> | ||
<ButtonPrimary | ||
disabled={attempt.status === 'processing'} | ||
block={true} | ||
onClick={run} | ||
mr={3} | ||
> | ||
Launch Web Session | ||
</ButtonPrimary> | ||
<ButtonSecondary | ||
disabled={attempt.status === 'processing'} | ||
onClick={onClose} | ||
> | ||
Cancel | ||
</ButtonSecondary> | ||
</Flex> | ||
</Dialog> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters