1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

Cli: Change Joplin Cloud login process (#9722)

This commit is contained in:
pedr 2024-03-11 06:58:54 -03:00 committed by GitHub
parent 9e0a0468b2
commit 56dde88003
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,6 +14,11 @@ const { cliUtils } = require('./cli-utils.js');
const md5 = require('md5');
import * as locker from 'proper-lockfile';
import { pathExists, writeFile } from 'fs-extra';
import { checkIfLoginWasSuccessful, generateApplicationConfirmUrl } from '@joplin/lib/services/joplinCloudUtils';
import Logger from '@joplin/utils/Logger';
import { uuidgen } from '@joplin/lib/uuid';
const logger = Logger.create('command-sync');
class Command extends BaseCommand {
@ -84,6 +89,33 @@ class Command extends BaseCommand {
Setting.setValue(`sync.${this.syncTargetId_}.auth`, response.access_token);
api.setAuthToken(response.access_token);
return true;
} else if (syncTargetMd.name === 'joplinCloud') {
const applicationAuthId = uuidgen();
const checkForCredentials = async () => {
try {
const applicationAuthUrl = `${Setting.value('sync.10.path')}/api/application_auth/${applicationAuthId}`;
const response = await checkIfLoginWasSuccessful(applicationAuthUrl);
if (response && response.success) {
return response;
}
return null;
} catch (error) {
logger.error(error);
throw error;
}
};
this.stdout(_('To allow Joplin to synchronise with Joplin Cloud, open this URL in your browser to authorise the application:'));
const confirmUrl = `${Setting.value('sync.10.website')}/applications/${applicationAuthId}/confirm`;
const urlWithClient = await generateApplicationConfirmUrl(confirmUrl);
this.stdout(urlWithClient);
const authorized = await this.prompt(_('Have you authorised the application login in the above URL?'), { booleanAnswerDefault: 'y' });
if (!authorized) return false;
const result = await checkForCredentials();
if (!result) return false;
return true;
}
this.stdout(_('Not authenticated with %s. Please provide any missing credentials.', syncTargetMd.label));