+// TODO: I am not sure if this function is implemented correctly.
+// There is currently no concept of migraiton between auth backends.
+bool Core::selectAuthenticator(const QString &backend)
+{
+ // Register all authentication backends.
+ registerAuthenticators();
+ auto auther = authenticator(backend);
+ if (!auther) {
+ QStringList authenticators;
+ std::transform(_registeredAuthenticators.begin(), _registeredAuthenticators.end(),
+ std::back_inserter(authenticators), [](const DeferredSharedPtr<Authenticator>& authenticator) {
+ return authenticator->displayName();
+ });
+ quWarning() << qPrintable(tr("Unsupported authenticator: %1").arg(backend));
+ quWarning() << qPrintable(tr("Supported authenticators are:")) << qPrintable(authenticators.join(", "));
+ return false;
+ }
+
+ QVariantMap settings = promptForSettings(auther.get());
+
+ Authenticator::State state = auther->init(settings);
+ switch (state) {
+ case Authenticator::IsReady:
+ saveAuthenticatorSettings(backend, settings);
+ quWarning() << qPrintable(tr("Switched authenticator to: %1").arg(backend));
+ return true;
+ case Authenticator::NotAvailable:
+ qCritical() << qPrintable(tr("Authenticator is not available: %1").arg(backend));
+ return false;
+ case Authenticator::NeedsSetup:
+ if (!auther->setup(settings)) {
+ quWarning() << qPrintable(tr("Unable to setup authenticator: %1").arg(backend));
+ return false;
+ }
+
+ if (auther->init(settings) != Authenticator::IsReady) {
+ quWarning() << qPrintable(tr("Unable to initialize authenticator: %1").arg(backend));
+ return false;
+ }
+
+ saveAuthenticatorSettings(backend, settings);
+ quWarning() << qPrintable(tr("Switched authenticator to: %1").arg(backend));
+ }
+
+ _authenticator = std::move(auther);
+ return true;
+}
+