Skip to content
This repository was archived by the owner on Apr 19, 2025. It is now read-only.

Commit 72803ea

Browse files
authored
Update README.md
1 parent 36861bd commit 72803ea

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

README.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This is a two-factor authentication package for *Laravel*. It is heavily inspire
99
- The current version of this package is only guaranteed to work with Laravel >= 5.5. Version 1.* of this package works with Laravel 5.4. Versions of Laravel prior to 5.4 have not been tested.
1010

1111
## Installation
12-
1 To install using *Composer* run:
12+
1. To install using *Composer* run:
1313
```
1414
composer require michaeldzjap/twofactor-auth
1515
```
@@ -19,23 +19,23 @@ composer require messagebird/php-rest-api
1919
```
2020
and don't forget to add your `MESSAGEBIRD_ACCESS_KEY` and `TWO_FACTOR_AUTH_DRIVER=messagebird` variables to the `.env`. If you instead wish to use the `'null'` driver (default) then do **NOT** define the `TWO_FACTOR_AUTH_DRIVER` variable in your `.env`.
2121

22-
2 Add the service provider to the `'providers'` array in `config/app.php`:
22+
2. Add the service provider to the `'providers'` array in `config/app.php`:
2323
```php
2424
MichaelDzjap\TwoFactorAuth\TwoFactorAuthServiceProvider::class
2525
```
26-
3 Run the following *artisan* command to publish the configuration, language and view files:
26+
3. Run the following *artisan* command to publish the configuration, language and view files:
2727
```
2828
php artisan vendor:publish
2929
```
3030
If you want to publish only one of these file groups, for instance if you don't need the views or language files, you can append one of the following commands to the *artisan* command: `--tag=config`, `--tag=lang` or `--tag-views`.
3131

32-
4 Run the following *artisan* command to run the database migrations
32+
4. Run the following *artisan* command to run the database migrations
3333
```
3434
php artisan migrate
3535
```
3636
This will add a `mobile` column to the `users` table and create a `two_factor_auths` table.
3737

38-
5 Add the following trait to your `User` model:
38+
5. Add the following trait to your `User` model:
3939
```php
4040
...
4141
use MichaelDzjap\TwoFactorAuth\TwoFactorAuthenticable;
@@ -60,7 +60,7 @@ $router->group([
6060
```
6161
The first route is the route the user will be redirected to once the two-factor authentication process has been initiated. The second route is used to verify the two-factor authentication token that is to be entered by the user. The `showTwoFactorForm` controller method does exactly what it says. There do exist cases where you might want to respond differently however. For instance, instead of loading a view you might just want to return a `json` response. In that case you can simply overwrite `showTwoFactorForm` in the `TwoFactorAuthController` to be discussed below.
6262

63-
1 Add the following import to `LoginController`:
63+
1. Add the following import to `LoginController`:
6464
```php
6565
...
6666
use MichaelDzjap\TwoFactorAuth\Contracts\TwoFactorProvider;
@@ -129,7 +129,7 @@ private function registerUserAndSendToken(User $user)
129129
```
130130
You can discard the third function if you do not want to send a two-factor authentication token automatically after a successful login attempt. Instead, you might want the user to instantiate this process from the form him/herself. In that case you would have to add the required route and controller method to trigger this function yourself. The best place for this would be the `TwoFactorAuthController` to be discussed next.
131131

132-
2 Add a `TwoFactorAuthController` in `app/Http/Controllers/Auth` with the following content:
132+
2. Add a `TwoFactorAuthController` in `app/Http/Controllers/Auth` with the following content:
133133
```php
134134
<?php
135135

@@ -164,7 +164,7 @@ class TwoFactorAuthController extends Controller
164164
protected $redirectTo = '/home';
165165
}
166166
```
167-
3 If you want to give textual feedback to the user when two-factor authentication fails due to an expired token or when throttling kicks in you may want to add this to `resources/views/auth/login.blade.php`:
167+
3. If you want to give textual feedback to the user when two-factor authentication fails due to an expired token or when throttling kicks in you may want to add this to `resources/views/auth/login.blade.php`:
168168
```php
169169
...
170170
<form class="form-horizontal" role="form" method="POST" action="{{ route('login') }}">
@@ -183,5 +183,27 @@ class TwoFactorAuthController extends Controller
183183
...
184184
```
185185

186+
## Using a Custom Provider
187+
Since the v2.1.0 release it is possible to user your own custom provider. To do so your provider needs to implement `MichaelDzjap\TwoFactorAuth\Contracts\TwoFactorProvider` (and possibly `MichaelDzjap\TwoFactorAuth\Contracts\SMSToken` if you want to send the authentication token via SMS).
188+
189+
1. Assuming the name of your custom provider is 'dummy', you should register it with `TwoFactorAuthManager` from a service provider (could be `\App\Providers\AppServiceProvider`):
190+
```php
191+
resolve(\MichaelDzjap\TwoFactorAuth\TwoFactorAuthManager)->extend('dummy', function ($app) {
192+
return new DummyProvider;
193+
});
194+
```
195+
2. Add an entry for you custom provider in the 'provider' array in *app/config/twofactor-auth.php*:
196+
```php
197+
...
198+
'dummy' => [
199+
'driver' => 'dummy',
200+
],
201+
...
202+
```
203+
3. Lastly, don't forget to change the name of the provider in your *.env*:
204+
```
205+
TWO_FACTOR_AUTH_DRIVER=dummy
206+
```
207+
186208
## Errors and Exceptions
187209
Unfortunately the *MessageBird* php api throws rather generic exceptions when the verification of a token fails. The only way to distinguish an expired token from an invalid token is by comparing their error messages, which obviously is not a very robust mechanism. The reason this is rather unfortunate is because in the case of an invalid token we want to give the user at least a few (3) changes to re-enter the token before throttling kicks in, whereas in the case of an expired token we just want to redirect to the login screen right away.

0 commit comments

Comments
 (0)