From 684c9285a6f06193a5ff1b7ef3421a2d7cd6f570 Mon Sep 17 00:00:00 2001
From: Ajay Bura <32841439+ajbura@users.noreply.github.com>
Date: Sun, 19 Jan 2025 21:30:13 +0530
Subject: [PATCH] add sso uia stage
---
src/app/components/ActionUIA.tsx | 17 +++-
src/app/components/uia-stages/SSOStage.tsx | 95 +++++++++++++++++++
src/app/components/uia-stages/index.ts | 1 +
.../features/settings/sessions/Sessions.tsx | 1 -
4 files changed, 109 insertions(+), 5 deletions(-)
create mode 100644 src/app/components/uia-stages/SSOStage.tsx
diff --git a/src/app/components/ActionUIA.tsx b/src/app/components/ActionUIA.tsx
index 88f0fe0e..b9cd122f 100644
--- a/src/app/components/ActionUIA.tsx
+++ b/src/app/components/ActionUIA.tsx
@@ -3,7 +3,8 @@ import { AuthDict, AuthType, IAuthData, UIAFlow } from 'matrix-js-sdk';
import { getUIAFlowForStages } from '../utils/matrix-uia';
import { useSupportedUIAFlows, useUIACompleted, useUIAFlow } from '../hooks/useUIAFlows';
import { UIAFlowOverlay } from './UIAFlowOverlay';
-import { PasswordStage } from './uia-stages';
+import { PasswordStage, SSOStage } from './uia-stages';
+import { useMatrixClient } from '../hooks/useMatrixClient';
export const SUPPORTED_IN_APP_UIA_STAGES = [AuthType.Password, AuthType.Sso];
@@ -14,13 +15,13 @@ export const pickUIAFlow = (uiaFlows: UIAFlow[]): UIAFlow | undefined => {
};
type ActionUIAProps = {
- userId: string;
authData: IAuthData;
ongoingFlow: UIAFlow;
action: (authDict: AuthDict) => void;
onCancel: () => void;
};
-export function ActionUIA({ userId, authData, ongoingFlow, action, onCancel }: ActionUIAProps) {
+export function ActionUIA({ authData, ongoingFlow, action, onCancel }: ActionUIAProps) {
+ const mx = useMatrixClient();
const completed = useUIACompleted(authData);
const { getStageToComplete } = useUIAFlow(authData, ongoingFlow);
@@ -35,7 +36,15 @@ export function ActionUIA({ userId, authData, ongoingFlow, action, onCancel }: A
>
{stageToComplete.type === AuthType.Password && (
+ )}
+ {stageToComplete.type === AuthType.Sso && stageToComplete.session && (
+ ();
+
+ const handleSubmit = useCallback(
+ () =>
+ submitAuthDict({
+ type: AuthType.Sso,
+ session,
+ }),
+ [submitAuthDict, session]
+ );
+
+ const handleContinue = () => {
+ const w = window.open(ssoRedirectURL, '_blank');
+ setSSOWindow(w ?? undefined);
+ };
+
+ useEffect(() => {
+ const handleMessage = (evt: MessageEvent) => {
+ if (ssoWindow && evt.data === 'authDone' && evt.source === ssoWindow) {
+ ssoWindow.close();
+ setSSOWindow(undefined);
+ handleSubmit();
+ }
+ };
+
+ window.addEventListener('message', handleMessage);
+ return () => {
+ window.removeEventListener('message', handleMessage);
+ };
+ }, [ssoWindow, handleSubmit]);
+
+ return (
+
+ );
+}
diff --git a/src/app/components/uia-stages/index.ts b/src/app/components/uia-stages/index.ts
index 9b158989..c422d988 100644
--- a/src/app/components/uia-stages/index.ts
+++ b/src/app/components/uia-stages/index.ts
@@ -4,4 +4,5 @@ export * from './EmailStage';
export * from './PasswordStage';
export * from './ReCaptchaStage';
export * from './RegistrationTokenStage';
+export * from './SSOStage';
export * from './TermsStage';
diff --git a/src/app/features/settings/sessions/Sessions.tsx b/src/app/features/settings/sessions/Sessions.tsx
index 1521315e..dcc69091 100644
--- a/src/app/features/settings/sessions/Sessions.tsx
+++ b/src/app/features/settings/sessions/Sessions.tsx
@@ -404,7 +404,6 @@ export function Sessions({ requestClose }: SessionsProps) {
>
{(ongoingFlow) => (