Cannot login with DAVx5 while using two-factor authentication

Nextcloud version (eg, 20.0.5): 24.0.9
Operating system and version (eg, Ubuntu 20.04): unknown - hosted environment
Apache or nginx version (eg, Apache 2.4.25): unknown - hosted environment
PHP version (eg, 7.4): 8.0.27

The issue you are facing:
I’m using two-factor authentication for some while now. Today i recognized, that my calendars are out of sync and that it didn’t change after manual sync. So i deleted my account in DAVx5 and wanted to create it again.

I created a new app password in my Nextcloud - Security settings, started my Nextcloud app on my Android phone and chose “Sync calendar & contacts” in “Settings”. Then DAVx5 opens and shows our Nextcloud “Connect to your account” page immediately.

First i chose the “Log in”-button, entered my username and my new app password and it said, that my credentials are wrong. Thought i did it there in the past but maybe i’m wrong. So i started again from the beginning and instead of choosing the “Log in”-button, i used the link “Alternative log in using app token” below that button. After adding my username and my new app password an internal server error shows up and i get an error in the nextcloud.log.

I have exactly the same behavior with the same phone but another nextcloud instance.
Do i just do it wrong?

Thanks a lot!
Nils

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. Create a new app password
  2. Choose “Sync calendar & contacts” in Android Nextcloud app settings
  3. Login with your new app password

The output of your Nextcloud log in Admin > Logging:

[index] Fehler: Exception: OC\Core\Service\LoginFlowV2Service::flowDoneWithAppPassword(): Argument #3 ($loginName) must be of type string, null given, called in /var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Controller/ClientFlowLoginV2Controller.php on line 227 in file '/var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Service/LoginFlowV2Service.php' line 189 at <<closure>>

0. /var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/AppFramework/App.php line 172
   OC\AppFramework\Http\Dispatcher->dispatch()
1. /var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/Route/Router.php line 298
   OC\AppFramework\App::main()
2. /var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/base.php line 1030
   OC\Route\Router->match()
3. /var/www/vhosts/no-domain.com/cloud.no-domain.com/index.php line 36
   OC::handleRequest()

POST /login/v2/apptoken
from xxx at 2023-02-16T08:14:15+00:00

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'trusted_proxies' => 
  array (
    0 => '127.0.0.1',
  ),
  'passwordsalt' => 'xxx',
  'secret' => 'xxx',
  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => 'cloud.no-domain.com',
  ),
  'datadirectory' => '/var/www/vhosts/no-domain.com/.nextcloud/data/91724b953bad',
  'dbtype' => 'mysql',
  'version' => '24.0.9.2',
  'overwrite.cli.url' => 'https://cloud.no-domain.com/',
  'htaccess.RewriteBase' => '/',
  'dbname' => 'nextcloud_1551bb69',
  'dbhost' => 'localhost:3306',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'xxx',
  'dbpassword' => 'xxx',
  'installed' => true,
  'instanceid' => 'xxx',
  'default_language' => 'de',
  'default_locale' => 'de_DE',
  'mail_smtpmode' => 'smtp',
  'mail_smtpsecure' => 'ssl',
  'mail_sendmailmode' => 'smtp',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_from_address' => 'noreply',
  'mail_domain' => 'no-domain.com',
  'mail_smtphost' => 'xxx',
  'mail_smtpport' => '465',
  'mail_smtpauth' => 1,
  'mail_smtpname' => 'noreply@no-domain.com',
  'mail_smtppassword' => 'xxx',
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'ldapIgnoreNamingRules' => false,
  'ldapProviderFactory' => 'OCA\\User_LDAP\\LDAPProviderFactory',
  'app_install_overwrite' => 
  array (
    0 => 'files_readmemd',
  ),
  'default_phone_region' => 'DE',
  'updater.release.channel' => 'stable',
  'skeletondirectory' => '',
  'templatedirectory' => '',
  'trashbin_retention_obligation' => 'auto, 180',
  'app.mail.smtp.timeout' => 45,
  'simpleSignUpLink.shown' => false,
  'profile.enabled' => false,
);

Output errors in nextcloud.log in /var/www/ or as admin user in top right menu, filtering for errors. Use a pastebin service if necessary.

nextcloud.log

{“reqId”:“gMEZNxqozbzjLz5dFyvF”,“level”:3,“time”:“2023-02-16T08:13:57+00:00”,“remoteAddr”:“xxx”,“user”:“–”,“app”:“index”,“method”:“POST”,“url”:“/login/v2/apptoken”,“message”:“OC\Core\Service\LoginFlowV2Service::flowDoneWithAppPassword(): Argument #3 ($loginName) must be of type string, null given, called in /var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Controller/ClientFlowLoginV2Controller.php on line 227 in file ‘/var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Service/LoginFlowV2Service.php’ line 189”,“userAgent”:“Mozilla/5.0 (Android 10; Mobile; rv:109.0) Gecko/109.0 Firefox/109.0”,“version”:“24.0.9.2”,“exception”:{“Exception”:“Exception”,“Message”:“OC\Core\Service\LoginFlowV2Service::flowDoneWithAppPassword(): Argument #3 ($loginName) must be of type string, null given, called in /var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Controller/ClientFlowLoginV2Controller.php on line 227 in file ‘/var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Service/LoginFlowV2Service.php’ line 189”,“Code”:0,“Trace”:[{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/AppFramework/App.php”,“line”:172,“function”:“dispatch”,“class”:“OC\AppFramework\Http\Dispatcher”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/Route/Router.php”,“line”:298,“function”:“main”,“class”:“OC\AppFramework\App”,“type”:“::”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/base.php”,“line”:1030,“function”:“match”,“class”:“OC\Route\Router”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/index.php”,“line”:36,“function”:“handleRequest”,“class”:“OC”,“type”:“::”}],“File”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/AppFramework/Http/Dispatcher.php”,“Line”:165,“Previous”:{“Exception”:“TypeError”,“Message”:“OC\Core\Service\LoginFlowV2Service::flowDoneWithAppPassword(): Argument #3 ($loginName) must be of type string, null given, called in /var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Controller/ClientFlowLoginV2Controller.php on line 227”,“Code”:0,“Trace”:[{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Controller/ClientFlowLoginV2Controller.php”,“line”:227,“function”:“flowDoneWithAppPassword”,“class”:“OC\Core\Service\LoginFlowV2Service”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/AppFramework/Http/Dispatcher.php”,“line”:225,“function”:“apptokenRedirect”,“class”:“OC\Core\Controller\ClientFlowLoginV2Controller”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/AppFramework/Http/Dispatcher.php”,“line”:133,“function”:“executeController”,“class”:“OC\AppFramework\Http\Dispatcher”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/AppFramework/App.php”,“line”:172,“function”:“dispatch”,“class”:“OC\AppFramework\Http\Dispatcher”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/Route/Router.php”,“line”:298,“function”:“main”,“class”:“OC\AppFramework\App”,“type”:“::”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/base.php”,“line”:1030,“function”:“match”,“class”:“OC\Route\Router”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/index.php”,“line”:36,“function”:“handleRequest”,“class”:“OC”,“type”:“::”}],“File”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Service/LoginFlowV2Service.php”,“Line”:189},“CustomMessage”:“–”}}

{“reqId”:“xpsomTYrjgNHx9aeHiJU”,“level”:3,“time”:“2023-02-16T08:14:15+00:00”,“remoteAddr”:“xxx”,“user”:“–”,“app”:“index”,“method”:“POST”,“url”:“/login/v2/apptoken”,“message”:“OC\Core\Service\LoginFlowV2Service::flowDoneWithAppPassword(): Argument #3 ($loginName) must be of type string, null given, called in /var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Controller/ClientFlowLoginV2Controller.php on line 227 in file ‘/var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Service/LoginFlowV2Service.php’ line 189”,“userAgent”:“Mozilla/5.0 (Android 10; Mobile; rv:109.0) Gecko/109.0 Firefox/109.0”,“version”:“24.0.9.2”,“exception”:{“Exception”:“Exception”,“Message”:“OC\Core\Service\LoginFlowV2Service::flowDoneWithAppPassword(): Argument #3 ($loginName) must be of type string, null given, called in /var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Controller/ClientFlowLoginV2Controller.php on line 227 in file ‘/var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Service/LoginFlowV2Service.php’ line 189”,“Code”:0,“Trace”:[{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/AppFramework/App.php”,“line”:172,“function”:“dispatch”,“class”:“OC\AppFramework\Http\Dispatcher”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/Route/Router.php”,“line”:298,“function”:“main”,“class”:“OC\AppFramework\App”,“type”:“::”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/base.php”,“line”:1030,“function”:“match”,“class”:“OC\Route\Router”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/index.php”,“line”:36,“function”:“handleRequest”,“class”:“OC”,“type”:“::”}],“File”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/AppFramework/Http/Dispatcher.php”,“Line”:165,“Previous”:{“Exception”:“TypeError”,“Message”:“OC\Core\Service\LoginFlowV2Service::flowDoneWithAppPassword(): Argument #3 ($loginName) must be of type string, null given, called in /var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Controller/ClientFlowLoginV2Controller.php on line 227”,“Code”:0,“Trace”:[{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Controller/ClientFlowLoginV2Controller.php”,“line”:227,“function”:“flowDoneWithAppPassword”,“class”:“OC\Core\Service\LoginFlowV2Service”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/AppFramework/Http/Dispatcher.php”,“line”:225,“function”:“apptokenRedirect”,“class”:“OC\Core\Controller\ClientFlowLoginV2Controller”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/AppFramework/Http/Dispatcher.php”,“line”:133,“function”:“executeController”,“class”:“OC\AppFramework\Http\Dispatcher”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/AppFramework/App.php”,“line”:172,“function”:“dispatch”,“class”:“OC\AppFramework\Http\Dispatcher”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/Route/Router.php”,“line”:298,“function”:“main”,“class”:“OC\AppFramework\App”,“type”:“::”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/base.php”,“line”:1030,“function”:“match”,“class”:“OC\Route\Router”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/index.php”,“line”:36,“function”:“handleRequest”,“class”:“OC”,“type”:“::”}],“File”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Service/LoginFlowV2Service.php”,“Line”:189},“CustomMessage”:“–”}}

{“reqId”:“0FBZU8ihfdG4gNuoZEm6”,“level”:3,“time”:“2023-02-16T08:18:52+00:00”,“remoteAddr”:“xxx”,“user”:“–”,“app”:“index”,“method”:“POST”,“url”:“/login/v2/apptoken”,“message”:“OC\Core\Service\LoginFlowV2Service::flowDoneWithAppPassword(): Argument #3 ($loginName) must be of type string, null given, called in /var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Controller/ClientFlowLoginV2Controller.php on line 227 in file ‘/var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Service/LoginFlowV2Service.php’ line 189”,“userAgent”:“Mozilla/5.0 (Android 10; Mobile; rv:109.0) Gecko/109.0 Firefox/109.0”,“version”:“24.0.9.2”,“exception”:{“Exception”:“Exception”,“Message”:“OC\Core\Service\LoginFlowV2Service::flowDoneWithAppPassword(): Argument #3 ($loginName) must be of type string, null given, called in /var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Controller/ClientFlowLoginV2Controller.php on line 227 in file ‘/var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Service/LoginFlowV2Service.php’ line 189”,“Code”:0,“Trace”:[{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/AppFramework/App.php”,“line”:172,“function”:“dispatch”,“class”:“OC\AppFramework\Http\Dispatcher”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/Route/Router.php”,“line”:298,“function”:“main”,“class”:“OC\AppFramework\App”,“type”:“::”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/base.php”,“line”:1030,“function”:“match”,“class”:“OC\Route\Router”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/index.php”,“line”:36,“function”:“handleRequest”,“class”:“OC”,“type”:“::”}],“File”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/AppFramework/Http/Dispatcher.php”,“Line”:165,“Previous”:{“Exception”:“TypeError”,“Message”:“OC\Core\Service\LoginFlowV2Service::flowDoneWithAppPassword(): Argument #3 ($loginName) must be of type string, null given, called in /var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Controller/ClientFlowLoginV2Controller.php on line 227”,“Code”:0,“Trace”:[{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Controller/ClientFlowLoginV2Controller.php”,“line”:227,“function”:“flowDoneWithAppPassword”,“class”:“OC\Core\Service\LoginFlowV2Service”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/AppFramework/Http/Dispatcher.php”,“line”:225,“function”:“apptokenRedirect”,“class”:“OC\Core\Controller\ClientFlowLoginV2Controller”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/AppFramework/Http/Dispatcher.php”,“line”:133,“function”:“executeController”,“class”:“OC\AppFramework\Http\Dispatcher”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/AppFramework/App.php”,“line”:172,“function”:“dispatch”,“class”:“OC\AppFramework\Http\Dispatcher”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/private/Route/Router.php”,“line”:298,“function”:“main”,“class”:“OC\AppFramework\App”,“type”:“::”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/lib/base.php”,“line”:1030,“function”:“match”,“class”:“OC\Route\Router”,“type”:“->”},{“file”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/index.php”,“line”:36,“function”:“handleRequest”,“class”:“OC”,“type”:“::”}],“File”:“/var/www/vhosts/no-domain.com/cloud.no-domain.com/core/Service/LoginFlowV2Service.php”,“Line”:189},“CustomMessage”:“–”}}

for DAVx5 you don’t need an app password.
You only need to follow little special procedure to connect using “Login Flow”

  1. Install the Nextcloud app for Android.
  2. Open the Settings of the Nextcloud app.
  3. Choose “Sync calendar & contacts”.
  4. DAVx⁵ will open with Nextcloud Login Flow.
  5. Continue DAVx⁵ setup as usual (see below).