Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is there any stp-by-step doc? #189

Open
realtebo opened this issue Oct 6, 2023 · 5 comments
Open

is there any stp-by-step doc? #189

realtebo opened this issue Oct 6, 2023 · 5 comments

Comments

@realtebo
Copy link

realtebo commented Oct 6, 2023

I appreciate your work a lot

But we cannot understand what to do after installation.

Aren't there any migration to run'

How to create routes? and how to intercept login to force redirect to view ?

Is there any public repo with a working laravel repo where is already integrated your package?

@yvomenezes
Copy link
Contributor

yvomenezes commented Feb 28, 2024

Hi. The package provides a middleware that you can add to the routes you want to enforce for the 2fa. You have to provide to the package a view to ask for the code and update its name in the config file, google2fa.php.

It is up to you to create the way for the user to activate the 2fa. You will need to add a column at the users table to store the secret. This column’s name should be added to the config file mentioned before.

@realtebo
Copy link
Author

I added the middleware to all protected routes. and the view for asking the OTP.
I added the column to users table and, when creating a user, a new google2fa_secret is generated for the user

But how can I intercept that user has not initialized it's authenticator app with the qr? Because actually the app after the login is requiring the otp, but not showing the qr

but if the google2fa_secret is NULL, the middleware go on without asking for 2FA at all.
How tell the middleware to redirect to a 'setup' page where the user is instructed to scan QR and insert first OTP?

This parte is undocumented, please, give me a direction.

@yvomenezes
Copy link
Contributor

That’s true. What you could do is to add a second column that tells whether the user has activated it or not and update the middleware to redirect for a view that shows the qrcode to scan in case it has not been activated.

@realtebo
Copy link
Author

realtebo commented Feb 28, 2024

ok, I understand. I did it.

Now ... I cannot understand if your package includes OR NOT a qr code generator.

Could you give me a simple example ?


use PragmaRX\Google2FAQRCode\Google2FA;
use PragmaRX\Google2FAQRCode\QRCode\Chillerlan;

...

        $google2fa = new Google2FA(
            new Chillerlan()
        );

        $qrCodeUrl = $google2fa->getQRCodeInline(
            config('app.name'),
            config($this->email),
            $this->google2fa_secret
        );


@realtebo
Copy link
Author

realtebo commented Feb 28, 2024

Ok, found !!! Installed the QR code package 'chillerlan/php-qrcode' in addition

composer require pragmarx/google2fa-laravel
composer require chillerlan/php-qrcode

In the user class

use PragmaRX\Google2FAQRCode\Google2FA;
use PragmaRX\Google2FAQRCode\QRCode\Chillerlan;

    public function getQrCodeUrlAttribute() {

        $google2fa = new Google2FA(
            new Chillerlan()
        );

        $qrCodeUrl = $google2fa->getQRCodeInline(
            config('app.name'),
            $this->email,
            $this->google2fa_secret
        );

        return $qrCodeUrl;
    }

in the blade

                    @unless(auth()->user()->google2fa_enabled)
                    <div class="form-group">
                        Scansiona il codice QR con l'app Google Authenticator

                        <br>
                        <img src="{{ auth()->user()->qr_code_url }}">
                    </div>
                    @endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants