nextcloud / twofactor_gateway

🔑 Second factor provider using an external messaging gateway (SMS, Telegram, Signal)
GNU Affero General Public License v3.0
109 stars 63 forks source link

Unhundled exception when setting up 2FA #129

Closed mmartinortiz closed 6 years ago

mmartinortiz commented 6 years ago

Two-Factor Gateway: 0.9.0 Nextcloud: 14.0.2 RC1

I've followed the instructions of the admin documentation for setting up the two-factor authentification using telegram. My Nextcloud server runs in a docker container, so I run the occ command with the following command:

docker exec nextcloud sudo -u abc /usr/bin/php -f /config/www/nextcloud/occ twofactorauth:gateway:configure telegram

It raises the following error:

The current PHP memory limit is below the recommended value of 512MB.
Using .
An unhandled exception has been thrown:
TypeError: Argument 1 passed to OCA\TwoFactorGateway\Service\Gateway\Telegram\GatewayConfig::setBotToken() must be of the type string, null given, called in /config/www/nextcloud/apps/twofactor_gateway/lib/Command/Configure.php on line 155 and defined in /config/www/nextcloud/apps/twofactor_gateway/lib/Service/Gateway/Telegram/GatewayConfig.php:54
Stack trace:
#0 /config/www/nextcloud/apps/twofactor_gateway/lib/Command/Configure.php(155): OCA\TwoFactorGateway\Service\Gateway\Telegram\GatewayConfig->setBotToken(NULL)
#1 /config/www/nextcloud/apps/twofactor_gateway/lib/Command/Configure.php(80): OCA\TwoFactorGateway\Command\Configure->configureTelegram(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#2 /config/www/nextcloud/3rdparty/symfony/console/Command/Command.php(251): OCA\TwoFactorGateway\Command\Configure->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /config/www/nextcloud/3rdparty/symfony/console/Application.php(946): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /config/www/nextcloud/3rdparty/symfony/console/Application.php(248): Symfony\Component\Console\Application->doRunCommand(Object(OCA\TwoFactorGateway\Command\Configure), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 /config/www/nextcloud/3rdparty/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 /config/www/nextcloud/lib/private/Console/Application.php(213): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 /config/www/nextcloud/console.php(96): OC\Console\Application->run()
#8 /config/www/nextcloud/occ(11): require_once('/config/www/nex...')
#9 {main}

Can I provide more useful information? I'm not sure how to proceed to getting 2FA working. (I did not try with other providers)

ChristophWurst commented 6 years ago

Did you enter a bot token when you were asked for it?

mmartinortiz commented 6 years ago

I was not asked for a token, I just got the exception after I run the command

Edit:

I've tried using the token as a second argument after telegram and as I expected it complains about "extra arguments"

ChristophWurst commented 6 years ago

That is unexpected. The telegram configure command definitely asks for a token: https://github.com/nextcloud/twofactor_gateway/blob/aa730883d763ab070c011ba505240d767fda5243/lib/Command/Configure.php#L157-L167

mmartinortiz commented 6 years ago

Interesting... the exception I get points to the line 150, and the function in the repository starts at line 157. I've checked both files (my local file and the one in the repo) and they are different.

Here is the diff:

102c102
<               $providerQuestion = new Question('Please choose a SMS provider (websms, playsms, clockworksms): ', 'websms');
---
>               $providerQuestion = new Question('Please choose a SMS provider (websms, playsms): ', 'websms');
139,149d138
<                       case 'clockworksms':
<                               $config->setProvider($provider);
<                               /** @var ClockworkSmsConfig $providerConfig */
<                               $providerConfig = $config->getProvider()->getConfig();
<
<                               $apitokenQuestion = new Question('Please enter your clockworksms api token: ');
<                               $apitoken = $helper->ask($input, $output, $apitokenQuestion);
<
<                               $providerConfig->setApiToken($apitoken);
<
<                               break;
169c158
< }
---
> }
\ No newline at end of file

I've disabled, removed and download the application again. The file I get installed is the same that I had previously. The appinfo/info.xml file indicates that the version is 0.9.0, though.

<?xml version="1.0"?>
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
        <id>twofactor_gateway</id>
        <name>Two-Factor Gateway</name>
        <summary>Two-factor gateway providers (SMS, Telegram, Signal)</summary>
        <description>A set of Nextcloud two-factor providers to send authentication codes via Signal, SMS and Telegram.</description>
        <version>0.9.0</version>
        <licence>agpl</licence>
        <author>Christoph Wurst</author>
        <namespace>TwoFactorGateway</namespace>
        <category>security</category>
        <website>https://github.com/nextcloud/twofactor_gateway</website>
        <bugs>https://github.com/nextcloud/twofactor_gateway/issues</bugs>
        <screenshot>https://raw.githubusercontent.com/ChristophWurst/twofactor_gateway/3f895bc997c1a3a38c9bae16ccae8bd499af864e/screenshots/settings.png</screenshot>
        <screenshot>https://raw.githubusercontent.com/ChristophWurst/twofactor_gateway/3f895bc997c1a3a38c9bae16ccae8bd499af864e/screenshots/challenge.png</screenshot>
        <dependencies>
                <php min-version="7.0" max-version="7.2"/>
                <nextcloud min-version="14" max-version="14"/>
        </dependencies>

        <two-factor-providers>
                <provider>OCA\TwoFactorGateway\Provider\SignalProvider</provider>
                <provider>OCA\TwoFactorGateway\Provider\SmsProvider</provider>
                <provider>OCA\TwoFactorGateway\Provider\TelegramProvider</provider>
        </two-factor-providers>
        <commands>
                <command>OCA\TwoFactorGateway\Command\Configure</command>
                <command>OCA\TwoFactorGateway\Command\Status</command>
                <command>OCA\TwoFactorGateway\Command\Test</command>
        </commands>
        <settings>
                <personal>OCA\TwoFactorGateway\Settings\PersonalSettings</personal>
        </settings>
</info>

How can I delete the applications cache? I want to make sure to force the the app to be downloaded again after I remove it.

ChristophWurst commented 6 years ago

Interesting... the exception I get points to the line 150, and the function in the repository star

Of course, because the master branch has change since the last release. You should be at this specific version: https://github.com/nextcloud/twofactor_gateway/blob/a5a7d4047ef80f485b81725fbca09afa6de20ea2/lib/Command/Configure.php#L146-L156.

Please don't change any files. If you do so and your installation breaks, you're on your own. I suggest to restore a backup with the previous state.

How can I delete the applications cache? I want to make sure to force the the app to be downloaded again after I remove it.

That functionality does not exist. You can try overwriting the app directory with the latest release tarball.

mmartinortiz commented 6 years ago

If the master branch contains a new development version I think it should have a different version number, like the 0.10.0 or just a 0.9.1-dev.

In any case, I've tried with sms and signal. In the case of signal I get a Using a localhost:5000 what I guess means that the argument is accepted. If I use sms I get an exception:

TypeError: Argument 1 passed to OCA\TwoFactorGateway\Service\Gateway\SMS\Provider\WebSmsConfig::setUser() must be of the type string, null given, called in /config/www/nextcloud/apps/twofactor_gateway/lib/Command/Configure.php on line 118 and defined in /config/www/nextcloud/apps/twofactor_gateway/lib/Service/Gateway/SMS/Provider/WebSmsConfig.php:52```

If I use a wrong gateway, I get a proper error message:

Invalid gateway noway



Could the problem be originated by the class `Question`?
ChristophWurst commented 6 years ago

If the master branch contains a new development version I think it should have a different version number, like the 0.10.0 or just a 0.9.1-dev.

No, because we need the version bumps to trigger database migrations. Of course we could use even numbers for releases and odd ones for dev versions, but that breaks semver, which I'm a big fan of.

May I ask you what terminal you're using? Sounds like yours is not interactive and thus the questions are not asked. This is weird tbh.

mmartinortiz commented 6 years ago

I've checked the terminal. I'm using bash, but I forgot to use the -ti parameters for docker (making it interactive). My fault :-\

Now I'm having the same problem described in this other issue, but I'll add information there.

Thanks for your help