From 0c9ff51ee161448085103f5f0a8b04c09fbdf5e2 Mon Sep 17 00:00:00 2001 From: Majan Date: Fri, 2 Feb 2024 22:45:54 -0800 Subject: [PATCH] sso login confirm for upload cross signing keys --- src/app/organisms/settings/AuthRequest.jsx | 109 ++++++++++++++++----- 1 file changed, 87 insertions(+), 22 deletions(-) diff --git a/src/app/organisms/settings/AuthRequest.jsx b/src/app/organisms/settings/AuthRequest.jsx index ca07c2a2..81366461 100644 --- a/src/app/organisms/settings/AuthRequest.jsx +++ b/src/app/organisms/settings/AuthRequest.jsx @@ -22,6 +22,46 @@ const getAuthId = (password) => ({ }, }); + +function SsoAuthRequest({ onComplete, makeRequest, session }) { + const [status, setStatus] = useState(false); + const mountStore = useStore(); + let clicked = false + const handleSso = async (e) => { + clicked = true + console.log(e, session) + const baseUrl = `${initMatrix.matrixClient.baseUrl}/_matrix/client/v3/auth/m.login.sso/fallback/web`; + window.open(`${baseUrl}?session=${session}`, "_blank"); + } + + const handleConfirm = async (e) => { + mountStore.setItem(true); + setStatus({ ongoing: true }); + await makeRequest({session}); + if (!mountStore.getItem()) return; + onComplete(true); + } + + return ( +
+
+ Use Single Sign On to continue + To continue, use Single Sign On to prove your identity. +
+ + +
+
+
+ ); +} +SsoAuthRequest.propTypes = { + onComplete: PropTypes.func.isRequired, + makeRequest: PropTypes.func.isRequired, + session: PropTypes.string.isRequired, +}; + + function AuthRequest({ onComplete, makeRequest }) { const [status, setStatus] = useState(false); const mountStore = useStore(); @@ -88,29 +128,54 @@ export const authRequest = async (title, makeRequest) => { lastUsedPassword = undefined; if (e.httpStatus !== 401 || e.data?.flows === undefined) return false; - const { flows } = e.data; - const canUsePassword = flows.find((f) => f.stages.includes('m.login.password')); - if (!canUsePassword) return false; + const { flows, session } = e.data; + const canUsePassword = flows.find((f) => f.stages.includes('m.login.password')) || false; - return new Promise((resolve) => { - let isCompleted = false; - openReusableDialog( - {title}, - (requestClose) => ( - { - isCompleted = true; - resolve(done); - requestClose(); - }} - makeRequest={makeRequest} - /> - ), - () => { - if (!isCompleted) resolve(false); - }, - ); - }); + let promise + if (canUsePassword) { + promise = new Promise((resolve) => { + let isCompleted = false; + openReusableDialog( + {title}, + (requestClose) => ( + { + isCompleted = true; + resolve(done); + requestClose(); + }} + makeRequest={makeRequest} + /> + ), + () => { + if (!isCompleted) resolve(false); + }, + ); + }); + } else { + promise = new Promise((resolve) => { + let isCompleted = false; + openReusableDialog( + {title}, + (requestClose) => ( + { + isCompleted = true; + resolve(done); + requestClose(); + }} + makeRequest={makeRequest} + /> + ), + () => { + if (!isCompleted) resolve(false); + }, + ); + }); + } + + return promise } };