1515 */
1616
1717#include " account.h"
18+ #include " cmd/tokencredentials.h"
1819#include " common/syncjournaldb.h"
1920#include " common/version.h"
2021#include " configfile.h" // ONLY ACCESS THE STATIC FUNCTIONS!
21- #include " httpcredentialstext.h"
2222#include " libsync/logger.h"
2323#include " libsync/theme.h"
2424#include " networkjobs/checkserverjobfactory.h"
@@ -51,9 +51,7 @@ struct CmdOptions
5151 QUrl server_url;
5252
5353 QString remoteFolder;
54- QString config_directory;
55- QString user;
56- QString password;
54+ QByteArray token;
5755 QString proxy;
5856 bool silent = false ;
5957 bool trustSSL = false ;
@@ -76,7 +74,6 @@ struct SyncCTX
7674 CmdOptions options;
7775 bool promptRemoveAllFiles;
7876 AccountPtr account;
79- QString user;
8077};
8178
8279/* If the selective sync list is different from before, we need to disable the read from db
@@ -192,18 +189,6 @@ void setupCredentials(SyncCTX &ctx)
192189 // 2. From options
193190 // 3. From prompt (if interactive)
194191
195- const auto &url = ctx.options .target_url ;
196- ctx.user = url.userName ();
197- QString password = url.password ();
198-
199- if (!ctx.options .user .isEmpty ()) {
200- ctx.user = ctx.options .user ;
201- }
202-
203- if (!ctx.options .password .isEmpty ()) {
204- password = ctx.options .password ;
205- }
206-
207192 if (!ctx.options .proxy .isNull ()) {
208193 QString host;
209194 uint32_t port = 0 ;
@@ -243,7 +228,7 @@ void setupCredentials(SyncCTX &ctx)
243228 f.close ();
244229 }
245230
246- ctx.account ->setCredentials (HttpCredentialsText::create (ctx.options .interactive , ctx. user , password ));
231+ ctx.account ->setCredentials (new TokenCredentials ( std::move (ctx.options .token ) ));
247232 if (ctx.options .trustSSL ) {
248233 QObject::connect (ctx.account ->accessManager (), &QNetworkAccessManager::sslErrors, qApp,
249234 [](QNetworkReply *reply, const QList<QSslError> &errors) { reply->ignoreSslErrors (errors); });
@@ -284,8 +269,7 @@ CmdOptions parseOptions(const QStringList &app_args)
284269 auto unsyncedfoldersOption = addOption ({ { QStringLiteral (" unsyncedfolders" ) }, QStringLiteral (" File containing the list of unsynced remote folders (selective sync)" ), QStringLiteral (" file" ) });
285270
286271 auto serverOption = addOption ({{QStringLiteral (" server" )}, QStringLiteral (" Use [url] as the location of the server." ), QStringLiteral (" url" )});
287- auto userOption = addOption ({ { QStringLiteral (" u" ), QStringLiteral (" user" ) }, QStringLiteral (" Use [name] as the login name" ), QStringLiteral (" name" ) });
288- auto passwordOption = addOption ({{QStringLiteral (" p" ), QStringLiteral (" password" )}, QStringLiteral (" Use [pass] as password" ), QStringLiteral (" password" )});
272+ auto tokenOption = addOption ({{QStringLiteral (" t" ), QStringLiteral (" token" )}, QStringLiteral (" Access token" ), QStringLiteral (" token" )});
289273
290274 auto nonInterActiveOption = addOption ({ { QStringLiteral (" non-interactive" ) }, QStringLiteral (" Do not block execution with interaction" ) });
291275 auto maxRetriesOption = addOption ({ { QStringLiteral (" max-sync-retries" ) }, QStringLiteral (" Retries maximum n times (default to 3)" ), QStringLiteral (" n" ) });
@@ -347,11 +331,8 @@ CmdOptions parseOptions(const QStringList &app_args)
347331 } else {
348332 options.server_url = options.target_url ;
349333 }
350- if (parser.isSet (userOption)) {
351- options.user = parser.value (userOption);
352- }
353- if (parser.isSet (passwordOption)) {
354- options.password = parser.value (passwordOption);
334+ if (parser.isSet (tokenOption)) {
335+ options.token = parser.value (tokenOption).toUtf8 ();
355336 }
356337 if (parser.isSet (excludeOption)) {
357338 options.exclude = parser.value (excludeOption);
@@ -417,16 +398,8 @@ int main(int argc, char **argv)
417398 ctx.options .server_url = ctx.options .server_url .adjusted (QUrl::RemoveUserInfo);
418399 ctx.options .target_url = ctx.options .target_url .adjusted (QUrl::RemoveUserInfo);
419400
420- const QUrl baseUrl = [&ctx] {
421- auto tmp = ctx.options .server_url ;
422- // Find the url leading to the dav root
423- QStringList splitted = tmp.path ().split (ctx.account ->davPath ());
424- tmp.setPath (splitted.value (0 ));
425- return tmp;
426- }();
427-
428401
429- ctx.account ->setUrl (baseUrl );
402+ ctx.account ->setUrl (ctx. options . server_url );
430403
431404 auto *checkServerJob = CheckServerJobFactory (ctx.account ->accessManager ()).startJob (ctx.account ->url (), qApp);
432405
@@ -460,24 +433,9 @@ int main(int argc, char **argv)
460433 exit (EXIT_FAILURE);
461434 }
462435
463- auto userJob = new JsonApiJob (ctx.account , QStringLiteral (" ocs/v1.php/cloud/user" ), {}, {}, nullptr );
464- QObject::connect (userJob, &JsonApiJob::finishedSignal, qApp, [userJob, ctx = ctx]() mutable {
465- const QJsonObject data = userJob->data ().value (QStringLiteral (" ocs" )).toObject ().value (QStringLiteral (" data" )).toObject ();
466- ctx.account ->setDavUser (data.value (QStringLiteral (" id" )).toString ());
467- ctx.account ->setDavDisplayName (data.value (QStringLiteral (" display-name" )).toString ());
468-
469- if (ctx.options .server_url == ctx.options .target_url ) {
470- // guess dav path
471- if (!ctx.options .target_url .path ().contains (ctx.account ->davPath ())) {
472- ctx.options .target_url = OCC::Utility::concatUrlPath (ctx.options .target_url , ctx.account ->davPath ());
473- }
474- }
475-
476- // much lower age than the default since this utility is usually made to be run right after a change in the tests
477- SyncEngine::minimumFileAgeForUpload = std::chrono::seconds (0 );
478- sync (ctx);
479- });
480- userJob->start ();
436+ // much lower age than the default since this utility is usually made to be run right after a change in the tests
437+ SyncEngine::minimumFileAgeForUpload = std::chrono::seconds (0 );
438+ sync (ctx);
481439 });
482440 capabilitiesJob->start ();
483441 } else {
0 commit comments