Skip to content

Commit b881c89

Browse files
committed
Merge branch 'master' of github.com:thecodework/two-factor-authentication
2 parents 3d9155c + dcd0514 commit b881c89

File tree

1 file changed

+27
-37
lines changed

1 file changed

+27
-37
lines changed

README.md

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,32 @@ This package lets you setup your two factor authentication for your existing lar
1313
- Google Authenticator [Android](https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&hl=en) - [iOS](https://itunes.apple.com/in/app/google-authenticator/id388497605?mt=8) or [Authy](https://www.authy.com/) mobile app
1414

1515
## Installation
16+
**1. Composer Install**
1617
```bash
1718
$ composer require thecodework/two-factor-authentication:0.1.0
1819
```
1920
Note: The current version of the package is beta release, so be careful before using it for production applications.
2021

21-
After requiring the package simply run
22-
```bash
23-
$ php artisan migrate
24-
```
25-
It will use the default User model and adds two columns `is_2fa_enabled` and `secret_key`
22+
**2. Add Service Provider**
23+
After requiring the package add `TwoFactorAuthenticationServiceProvider::class` into providors array in `app.php` confi file
2624

27-
To publish config file
28-
```
29-
$ php artisan vendor:publish --provider="Thecodework\TwoFactorAuthentication\TwoFactorAuthenticationServiceProvider" --tag=config
30-
```
31-
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.
32-
The config file will look like this and have following configurable option.
3325
```php
34-
/*
35-
* Specify redirect url after when token authentication
36-
* is successfull.
37-
*/
38-
'redirect_to' => '/home',
39-
40-
/*
41-
* Account name which will be used as label to show on
42-
* authenticator mobile application.
43-
*/
44-
'account_name' => 'Thecodework 2FA',
45-
46-
/*
47-
* Currntly Support 'Sha1'
48-
* The library works with the Google Authenticator application
49-
* for iPhone and Android. Google only supports SHA-1 digest algorithm,
50-
* 30 second period and 6 digits OTP. Other values for these parameters
51-
* are ignored by the Google Authenticator application.
52-
*/
53-
'digest_algorithm' => 'sha1',
26+
[
27+
'providers' => [
28+
//...
29+
Thecodework\TwoFactorAuthentication\TwoFactorAuthenticationServiceProvider::class
30+
]
31+
]
32+
```
5433

55-
/*
56-
* Number of digits can be max 30
57-
* To Support Google Authenticator
58-
*/
59-
'number_of_digits' => 8,
34+
**3. Run Migrations**
35+
Now run the migration
36+
```bash
37+
$ php artisan migrate
6038
```
39+
It will use the default User model and adds two columns `is_2fa_enabled` and `secret_key`.
6140

41+
**4. Add `AuthenticatesUserWith2FA` trait in the LoginController**
6242
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.
6343

6444
The final snippet will look like this.
@@ -67,7 +47,17 @@ use AuthenticatesUsers, AuthenticatesUsersWith2FA {
6747
AuthenticatesUsersWith2FA::authenticated insteadof AuthenticatesUsers;
6848
}
6949
```
70-
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.
50+
Note: Don't forget to include use statement `use Thecodework\TwoFactorAuthentication\AuthenticatesUsersWith2FA` in the header.
51+
52+
**5. Publish the ConfigFile**
53+
Finally publish config file
54+
```
55+
$ php artisan vendor:publish --provider="Thecodework\TwoFactorAuthentication\TwoFactorAuthenticationServiceProvider" --tag=config
56+
```
57+
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.
58+
**6. Setup 2FA for user**
59+
60+
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.
7161
Scan that code and click **Enable Two Factor Authentication**.
7262

7363
Now 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 commit comments

Comments
 (0)