0
votes

I have implemented two factor authentication by the below link.

https://github.com/antonioribeiro/google2fa

Its works fine for me. My question is in that google2fa, there is one line.

To use the two factor authentication, your user will have to install a Google Authenticator compatible app. 

How to make the each users to install this app, then only you will get the google authenticator 2 factor authentication code.

Is it possible. And also how to implement two factor authentication via OTP in laravel. ie. OTP send via SMS. Please explain how to do?

Thanks in advance.

3
You ask them to do so. Am I missing something or? - Ivanka Todorova

3 Answers

1
votes

Installation

1. Composer Install

bash $ composer require thecodework/two-factor-authentication

2. Add Service Provider

After requiring the package add TwoFactorAuthenticationServiceProvider::class into providors array in app.php confi file

php [ 'providers' => [ //... Thecodework\TwoFactorAuthentication\TwoFactorAuthenticationServiceProvider::class ] ]

3. Run Migrations

Now run the migration bash $ php artisan migrate It will use the default User model and adds two columns is_2fa_enabled and secret_key.

4. Add AuthenticatesUserWith2FA trait in the LoginController

Now the config file is placed. The last thing to do is addding AuthenticatesUsersWith2FA trait in the Http/Controllers/Auth/LoginController.php file which helps to stop user at verify-2fa page to enter TOTP token after each login.

The final snippet will look like this. php use AuthenticatesUsers, AuthenticatesUsersWith2FA { AuthenticatesUsersWith2FA::authenticated insteadof AuthenticatesUsers; } Note: Don't forget to include use statement use Thecodework\TwoFactorAuthentication\AuthenticatesUsersWith2FA in the header.

5. Publish the ConfigFile

Finally publish config file $ php artisan vendor:publish --provider="Thecodework\TwoFactorAuthentication\TwoFactorAuthenticationServiceProvider" --tag=config Once the config file is published you can navigate to config directory of your application and look for 2fa-config.php file and change configuration as you want.

6. Setup 2FA for user

• Enable 2FA

Now login to the application and visit /setup-2fa/ route, which will show a barcode which can be scanned either using Google Authenticator or Authy mobile application as described above. Scan that code and click Enable Two Factor Authentication.

• Disable 2FA

To disable Two Factor, visit /setup-2fa route, which will now show a Disable Two Factor Authentication button. Click to disable 2FA for your account.

7. Testing 2FA

Now to test 2FA, perform logout and log back in again, it will ask you to enter Token which can be obtain from the authenticator mobile application. Enter the token and you're logged in.

0
votes

I have created for two-factor authentication for laravel, which allows you to send two-factor authentication tokens via SMS as well. Just visit the following link for installation instructions and examples.

I have also created a demo application which has two-factor authentication implemented by default.

0
votes

If you don't want to use any external package for this, simple steps would be sending an OTP on the user's email. Setup outlines would be -

  1. Adding a two factor form
  2. Creating a mailable
  3. Creating DB migrations
  4. Setting up controller and routes

A complete article on same is here - https://bootsity.com/laravel/implementing-two-factor-authentication-in-laravel-applications