RobThree/TwoFactorAuth

Location of MyProvider class when using phpqrcode and composer

D4V3M0NK opened this issue ยท 10 comments

Am loving the fact that this is so easy to use, many congratulations sir.

I have one question regarding the MyProvider.php class location when using PHPQRCode as per qr-code-providers

  1. I've placed the phpqrcode.php file in the same (composer) folder as TwoFactorAuth.php (./vendor/robthree/twofactorauth/lib)

  2. I've created the MyProvider.php file in the Providers/Qr folder (./vendor/robthree/twofactorauth/lib/Providers/Qr/MyProvider.php).

    1. The notes refer to that file named as myprovider.php when creating it, but I believe it should be MyProvider.php?
    2. I also believe that the namespace should be placed above the require/require_once?
  3. I've then taken your demo page, added my composer autoload.php to it and tried to get it working, but every time I attempt to run it, I get a missing phpqrcode.php file

Warning: require_once(../../phpqrcode.php): failed to open stream: No such file or directory in /var/www/vendor/robthree/twofactorauth/lib/Providers/Qr/MyProvider.php on line 3

Fatal error: require_once(): Failed opening required '../../phpqrcode.php' (include_path='.:/usr/share/php:/var/www/html/inc') in /var/www/vendor/robthree/twofactorauth/lib/Providers/Qr/MyProvider.php on line 3

  • Am I missing something really obvious here?

  • Should I not have placed those files in the vendor folder, but elsewhere in my application?

  • I've attached a screenshot of my vendor folder structure in the hope that assists?
    Screenshot from 2020-04-27 11-34-20

I've also amended the demo page - which works fine with or without autoloading composer - with the PHPQRCode implementation and that fails with the same error

The only way that I could get this working is to place the following at the top of my MyProvider.php file:
require_once __DIR__ . '/../../phpqrcode.php';

.. and then that leads to a

Fatal error: Uncaught Error: Class 'RobThree\Auth\Providers\Qr\QRCode' not found in /var/www/vendor/robthree/twofactorauth/lib/Providers/Qr/MyProvider.php:24

There appears to be a resolution to this at SO but I can't get that working as yet.

I also note, with some interest, that @willpower232 has BaconQrCode nearly working with this pull request - any updates on that? Ideally I want to be able to generate QrCodes locally...

Are you not using a composer-powered framework like Laravel?

It sounds like you aren't using namespaces quite right or need some use statements at the top of your new provider.

I've got this is in a test environment at the moment @willpower232 - basic server with PHP and composer installed upon it as I'm investigating it's use. I've followed @RobThree's instructions to the tee (along with using some references from your pages) but it just doesn't seem to work.

Also, I don't believe using Laravel is a requirement, is it?

Laravel isn't a requirement but it or another composer-powered framework would probably get you started easier.

Ordinarily, you wouldn't add files to the vendor folder yourself so that composer could be fully responsible for managing it.

I think you should keep your provider outside of the vendor folder completely with no namespace at the top of it. Then I would have an index.php next to it which looked something like this

<?php

require 'vendor/autoload.php';

require 'MyProvider.php';

$provider = new MyProvider();

$twoFa = new RobThree\Auth\TwoFactorAuth($issuer, 6, 30, 'sha1', $provider);

Hope this makes sense

Hi.

Little late to the party, sorry 'bout that.

I think @willpower232 is correct here. Did you solve your problem yet @D4V3M0NK ?

Thanks for all your help - finally (!) got the PHP QrCode generation working locally this evening. Thanks for all your guidance!

All credit to @willpower232 ๐Ÿ‘Š ๐Ÿ‘

๐Ÿ™