-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Desktop: Change Joplin Cloud login process to allow MFA via browser (#…
…9445) Co-authored-by: Laurent Cozic <laurent22@users.noreply.github.com>
- Loading branch information
Showing
15 changed files
with
347 additions
and
124 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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.login-page { | ||
|
||
display: flex; | ||
flex-direction: column; | ||
height: 100%; | ||
background-color: var(--joplin-background-color); | ||
color: var(--joplin-color); | ||
|
||
> .page-container { | ||
height: calc(100% - (var(--joplin-margin) * 2)); | ||
flex: 1; | ||
padding: var(--joplin-config-screen-padding); | ||
|
||
> .text { | ||
font-size: var(--joplin-font-size); | ||
} | ||
|
||
> .buttons-container { | ||
margin-bottom: calc(var(--joplin-font-size) * 2); | ||
display: flex; | ||
|
||
> button:first-child { | ||
margin-right: calc(var(--joplin-font-size) * 2); | ||
} | ||
} | ||
|
||
> .bold { | ||
font-weight: bold; | ||
font-size: calc(var(--joplin-font-size) * 1.3); | ||
} | ||
} | ||
} |
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,115 @@ | ||
import { useEffect, useMemo, useReducer, useState } from 'react'; | ||
import ButtonBar from './ConfigScreen/ButtonBar'; | ||
import { _ } from '@joplin/lib/locale'; | ||
import { clipboard } from 'electron'; | ||
import Button, { ButtonLevel } from './Button/Button'; | ||
const bridge = require('@electron/remote').require('./bridge').default; | ||
import { uuidgen } from '@joplin/lib/uuid'; | ||
import { Dispatch } from 'redux'; | ||
import { reducer, defaultState, generateApplicationConfirmUrl, checkIfLoginWasSuccessful } from '@joplin/lib/services/joplinCloudUtils'; | ||
import { AppState } from '../app.reducer'; | ||
import Logger from '@joplin/utils/Logger'; | ||
|
||
const logger = Logger.create('JoplinCloudLoginScreen'); | ||
const { connect } = require('react-redux'); | ||
|
||
interface Props { | ||
dispatch: Dispatch; | ||
joplinCloudWebsite: string; | ||
joplinCloudApi: string; | ||
} | ||
|
||
const JoplinCloudScreenComponent = (props: Props) => { | ||
|
||
const confirmUrl = (applicationAuthId: string) => `${props.joplinCloudWebsite}/applications/${applicationAuthId}/confirm`; | ||
const applicationAuthUrl = (applicationAuthId: string) => `${props.joplinCloudApi}/api/application_auth/${applicationAuthId}`; | ||
|
||
const [intervalIdentifier, setIntervalIdentifier] = useState(undefined); | ||
const [state, dispatch] = useReducer(reducer, defaultState); | ||
|
||
const applicatioAuthId = useMemo(() => uuidgen(), []); | ||
|
||
const periodicallyCheckForCredentials = () => { | ||
if (intervalIdentifier) return; | ||
|
||
const interval = setInterval(async () => { | ||
try { | ||
const response = await checkIfLoginWasSuccessful(applicationAuthUrl(applicatioAuthId)); | ||
if (response && response.success) { | ||
dispatch({ type: 'COMPLETED' }); | ||
clearInterval(interval); | ||
} | ||
} catch (error) { | ||
logger.error(error); | ||
dispatch({ type: 'ERROR', payload: error.message }); | ||
clearInterval(interval); | ||
} | ||
}, 2 * 1000); | ||
|
||
setIntervalIdentifier(interval); | ||
}; | ||
|
||
const onButtonUsed = () => { | ||
if (state.next === 'LINK_USED') { | ||
dispatch({ type: 'LINK_USED' }); | ||
} | ||
periodicallyCheckForCredentials(); | ||
}; | ||
|
||
const onAuthorizeClicked = async () => { | ||
const url = await generateApplicationConfirmUrl(confirmUrl(applicatioAuthId)); | ||
bridge().openExternal(url); | ||
onButtonUsed(); | ||
}; | ||
|
||
const onCopyToClipboardClicked = async () => { | ||
const url = await generateApplicationConfirmUrl(confirmUrl(applicatioAuthId)); | ||
clipboard.writeText(url); | ||
onButtonUsed(); | ||
}; | ||
|
||
useEffect(() => { | ||
return () => { | ||
clearInterval(intervalIdentifier); | ||
}; | ||
}, [intervalIdentifier]); | ||
|
||
return ( | ||
<div className="login-page"> | ||
<div className="page-container"> | ||
<p className="text">{_('To allow Joplin to synchronise with Joplin Cloud, open this URL in your browser to authorise the application:')}</p> | ||
<div className="buttons-container"> | ||
<Button | ||
onClick={onAuthorizeClicked} | ||
title={_('Authorise')} | ||
iconName='fa fa-external-link-alt' | ||
level={ButtonLevel.Primary} | ||
/> | ||
<Button | ||
onClick={onCopyToClipboardClicked} | ||
title={_('Copy link to website')} | ||
iconName='fa fa-clone' | ||
level={ButtonLevel.Secondary} | ||
/> | ||
|
||
</div> | ||
<p className={state.className}>{state.message()} | ||
{state.active === 'ERROR' ? ( | ||
<span className={state.className}>{state.errorMessage}</span> | ||
) : null} | ||
</p> | ||
{state.active === 'LINK_USED' ? <div id="loading-animation" /> : null} | ||
</div> | ||
<ButtonBar onCancelClick={() => props.dispatch({ type: 'NAV_BACK' })} /> | ||
</div> | ||
); | ||
}; | ||
|
||
const mapStateToProps = (state: AppState) => { | ||
return { | ||
joplinCloudWebsite: state.settings['sync.10.website'], | ||
joplinCloudApi: state.settings['sync.10.path'], | ||
}; | ||
}; | ||
|
||
export default connect(mapStateToProps)(JoplinCloudScreenComponent); |
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
Oops, something went wrong.