From c4ca55d2cf90e061ed3458b5d005333238b2728c Mon Sep 17 00:00:00 2001 From: Alex Plotnick Date: Fri, 10 Jun 2022 14:20:22 -0600 Subject: [PATCH 1/7] Add client authn verification page --- app/pages/ClientVerifyPage.tsx | 47 ++++++++++++++++++++++++++++++++++ app/routes.tsx | 5 ++++ 2 files changed, 52 insertions(+) create mode 100644 app/pages/ClientVerifyPage.tsx diff --git a/app/pages/ClientVerifyPage.tsx b/app/pages/ClientVerifyPage.tsx new file mode 100644 index 0000000000..8fe2d7998b --- /dev/null +++ b/app/pages/ClientVerifyPage.tsx @@ -0,0 +1,47 @@ +import { useSearchParams } from 'react-router-dom' + +import { useApiMutation } from '@oxide/api' +import { Button, Success16Icon, Warning12Icon } from '@oxide/ui' + +import { useToast } from '../hooks' + +/** + * Client verification success page + */ +export default function ClientVerifyPage() { + const [searchParams] = useSearchParams() + const addToast = useToast() + const confirmPost = useApiMutation('clientConfirm', { + onSuccess: () => { + addToast({ + title: 'Client verified', + icon: , + timeout: 4000, + }) + }, + onError: () => { + addToast({ + title: 'Verification failed', + icon: , + variant: 'error', + timeout: 4000, + }) + }, + }) + const userCode = searchParams.get('user_code') + + return ( +
+

Client verification

+

User code: {userCode}

+ +
+ ) +} diff --git a/app/routes.tsx b/app/routes.tsx index d70bace7ed..6c343258f5 100644 --- a/app/routes.tsx +++ b/app/routes.tsx @@ -11,6 +11,7 @@ import OrgLayout from './layouts/OrgLayout' import ProjectLayout from './layouts/ProjectLayout' import RootLayout from './layouts/RootLayout' import SettingsLayout from './layouts/SettingsLayout' +import ClientVerifyPage from './pages/ClientVerifyPage' import LoginPage from './pages/LoginPage' import NotFound from './pages/NotFound' import OrgsPage from './pages/OrgsPage' @@ -48,6 +49,10 @@ export const Router = () => ( } /> + }> + } /> + + } /> }> From 1204ba2430108ac14b17bb109c702abc21ee896d Mon Sep 17 00:00:00 2001 From: Alex Plotnick Date: Mon, 27 Jun 2022 15:23:16 -0600 Subject: [PATCH 2/7] Update for renamed device auth endpoints --- ...ClientVerifyPage.tsx => DeviceAuthVerifyPage.tsx} | 12 ++++++------ app/routes.tsx | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) rename app/pages/{ClientVerifyPage.tsx => DeviceAuthVerifyPage.tsx} (76%) diff --git a/app/pages/ClientVerifyPage.tsx b/app/pages/DeviceAuthVerifyPage.tsx similarity index 76% rename from app/pages/ClientVerifyPage.tsx rename to app/pages/DeviceAuthVerifyPage.tsx index 8fe2d7998b..2c4d6b509a 100644 --- a/app/pages/ClientVerifyPage.tsx +++ b/app/pages/DeviceAuthVerifyPage.tsx @@ -6,22 +6,22 @@ import { Button, Success16Icon, Warning12Icon } from '@oxide/ui' import { useToast } from '../hooks' /** - * Client verification success page + * Device authorization verification page */ -export default function ClientVerifyPage() { +export default function DeviceAuthVerifyPage() { const [searchParams] = useSearchParams() const addToast = useToast() - const confirmPost = useApiMutation('clientConfirm', { + const confirmPost = useApiMutation('deviceAuthConfirm', { onSuccess: () => { addToast({ - title: 'Client verified', + title: 'Token authorized', icon: , timeout: 4000, }) }, onError: () => { addToast({ - title: 'Verification failed', + title: 'Token denied', icon: , variant: 'error', timeout: 4000, @@ -32,7 +32,7 @@ export default function ClientVerifyPage() { return (
-

Client verification

+

Device authorization

User code: {userCode}

From 3cd3b5113858f7136ab86e717cc36deb632863ad Mon Sep 17 00:00:00 2001 From: David Crespo Date: Tue, 28 Jun 2022 23:01:09 -0500 Subject: [PATCH 6/7] use omicron version that's on main now that it's merged --- OMICRON_VERSION | 2 +- libs/api/__generated__/OMICRON_VERSION | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OMICRON_VERSION b/OMICRON_VERSION index 7a85e4cafe..c31860bbc7 100644 --- a/OMICRON_VERSION +++ b/OMICRON_VERSION @@ -1 +1 @@ -4dc8037377b68e982fa4c45a2a3a4075779b5624 \ No newline at end of file +1fa8d6d475bd9ba51f0fb045721be6fe20a74dbb \ No newline at end of file diff --git a/libs/api/__generated__/OMICRON_VERSION b/libs/api/__generated__/OMICRON_VERSION index e4e3ae72f7..f8ab0a55b8 100644 --- a/libs/api/__generated__/OMICRON_VERSION +++ b/libs/api/__generated__/OMICRON_VERSION @@ -1,2 +1,2 @@ # generated file. do not update manually. see docs/update-pinned-api.md -4dc8037377b68e982fa4c45a2a3a4075779b5624 +1fa8d6d475bd9ba51f0fb045721be6fe20a74dbb From 6c925242342cb87f44052e2494258ce00270977e Mon Sep 17 00:00:00 2001 From: David Crespo Date: Wed, 29 Jun 2022 14:17:24 -0500 Subject: [PATCH 7/7] quick polish on auth and success state --- app/pages/DeviceAuthSuccessPage.tsx | 17 +++++++++++++++++ app/pages/DeviceAuthVerifyPage.tsx | 22 ++++++++++------------ app/routes.tsx | 6 ++++-- libs/api-mocks/msw/handlers.ts | 10 ++++++++++ 4 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 app/pages/DeviceAuthSuccessPage.tsx diff --git a/app/pages/DeviceAuthSuccessPage.tsx b/app/pages/DeviceAuthSuccessPage.tsx new file mode 100644 index 0000000000..dd90a992c0 --- /dev/null +++ b/app/pages/DeviceAuthSuccessPage.tsx @@ -0,0 +1,17 @@ +import { Success16Icon } from '@oxide/ui' + +/** + * Device authorization success page + */ +export default function DeviceAuthSuccessPage() { + return ( +
+

Device authentication

+

+ + Success! +

+

Your device is now logged in.

+
+ ) +} diff --git a/app/pages/DeviceAuthVerifyPage.tsx b/app/pages/DeviceAuthVerifyPage.tsx index dc17e4901d..5d01f17b17 100644 --- a/app/pages/DeviceAuthVerifyPage.tsx +++ b/app/pages/DeviceAuthVerifyPage.tsx @@ -1,7 +1,7 @@ -import { useSearchParams } from 'react-router-dom' +import { useNavigate, useSearchParams } from 'react-router-dom' import { useApiMutation } from '@oxide/api' -import { Button, Success16Icon, Warning12Icon } from '@oxide/ui' +import { Button, Warning12Icon } from '@oxide/ui' import { useToast } from '../hooks' @@ -10,14 +10,11 @@ import { useToast } from '../hooks' */ export default function DeviceAuthVerifyPage() { const [searchParams] = useSearchParams() + const navigate = useNavigate() const addToast = useToast() const confirmPost = useApiMutation('deviceAuthConfirm', { onSuccess: () => { - addToast({ - title: 'Token authorized', - icon: , - timeout: 4000, - }) + navigate('/device/success') }, onError: () => { addToast({ @@ -31,19 +28,20 @@ export default function DeviceAuthVerifyPage() { const userCode = searchParams.get('user_code') return ( -
-

Device authorization

-

User code: {userCode}

+
+

Device authentication

+

Make sure this code matches the one shown on the device you are authenticating.

+

{userCode}

) diff --git a/app/routes.tsx b/app/routes.tsx index 861713b28e..fff239bee9 100644 --- a/app/routes.tsx +++ b/app/routes.tsx @@ -9,6 +9,7 @@ import OrgLayout from './layouts/OrgLayout' import ProjectLayout from './layouts/ProjectLayout' import RootLayout from './layouts/RootLayout' import SettingsLayout from './layouts/SettingsLayout' +import DeviceAuthSuccessPage from './pages/DeviceAuthSuccessPage' import DeviceAuthVerifyPage from './pages/DeviceAuthVerifyPage' import LoginPage from './pages/LoginPage' import NotFound from './pages/NotFound' @@ -45,8 +46,9 @@ export const Router = () => ( } /> - }> - } /> + }> + } /> + } /> } /> diff --git a/libs/api-mocks/msw/handlers.ts b/libs/api-mocks/msw/handlers.ts index 978769d113..62c11400b5 100644 --- a/libs/api-mocks/msw/handlers.ts +++ b/libs/api-mocks/msw/handlers.ts @@ -841,4 +841,14 @@ export const handlers = [ rest.get | GetErr>('/api/users', (req, res) => { return res(json(paginated(req.url.search, db.users))) }), + + rest.post, never, PostErr>( + '/api/device/confirm', + (req, res, ctx) => { + if (req.body.user_code === 'BADD-CODE') { + return res(ctx.status(404)) + } + return res(ctx.status(200)) + } + ), ]