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

Commit 7f0c706

Browse files
committed
Merge branch 'develop'
2 parents 659cee1 + 371ee9d commit 7f0c706

File tree

9 files changed

+35
-33
lines changed

9 files changed

+35
-33
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,14 @@ A two-factor authentication package for _Laravel_ >= 5.5
99
## Description
1010
This is a two-factor authentication package for _Laravel_. It is heavily inspired by the [Laravel Two-Factor Authentication](https://github.com/srmklive/laravel-twofactor-authentication) package. The main differences between this package and the aforementioned package are:
1111

12-
- This package currently only works with the *MessageBird Verify* api or the `'null'` driver that goes through all the steps of the two-factor authentication process without actually doing any real verification. This could be useful for testing purposes.
12+
- This package currently only works out of the box with the *MessageBird Verify* api or the `'null'` driver that goes through all the steps of the two-factor authentication process without actually doing any real verification. This could be useful for testing purposes. You can however, specify a custom provider yourself.
1313
- This package uses throttling to limit the number of unsuccessful authentication attempts in a certain amount of time.
1414
- 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.
1515

1616
## Important
17-
From _Laravel_ 5.8 and onwards, the default is to use `bigIncrements` instead of `increments` for the `id` column on the `users` table. As such, the default for this package is to use the same convention for the `user_id` column on the `two_factor_auths` table. If this is not what you want, you can change this in the published config file by setting the "big_int" option to `false`.
17+
From _Laravel_ 5.8 and onwards, the default is to use `bigIncrements` instead of `increments` for the `id` column on the `users` table. As such, the default for this package is to use the same convention for the `user_id` column on the `two_factor_auths` table. If this is not what you want, you can change this to your liking by modifying the migration files that are published for this package.
1818

19-
For users who have already installed this package and hence, already have ran the migrations for this package there are essentially two different scenarios:
20-
21-
1. You upgrade from _Laravel_ < 5.8 to 5.8 or later and have decided to keep using `increments` for the `id` column on the `users` table: You don't have to do anything. You might want to [change](#optional-correction) the signature of the `user_id` column on the `two_factor_auths` table from `increments` to `unsignedInteger` though.
22-
23-
2. You upgrade from _Laravel_ < 5.8 to 5.8 or later and have decided to make the switch to `bigIncrements` for the `id` column on the `users` table: You will have to make and run your own migration in order to update the `user_id` column on the `two_factor_auths` table appropriately.
19+
Publishing the package's migration files allows for more flexibility with regards to customising your database structure. However, it could also cause complications if you already have ran migrations as part of installing previous versions of this package. In this case you simply might want to bypass running the migrations again or only run them when in a specific environment. The `Schema::hasColumn()` and `Schema::hasTable()` methods should be of use here.
2420

2521
### Optional correction
2622
Versions of this package prior to v2.3.0 incorrectly created the `user_id` column on the `two_factor_auths` table using `increments` instead of `unsignedInteger`. Practically speaking, this error is of no concern. Although there is no need to have a _primary_ key for the `user_id` column, it doesn't cause any problems either. However, if for some reason you don't like this idea, it is safe to remove the _primary_ key using a migration of the form
@@ -95,7 +91,7 @@ If you want to publish only one of these file groups, for instance if you don't
9591

9692
4. **Important**: Make sure you do this step _before_ you run any migrations for this package, as otherwise it might give you unexpected results.
9793

98-
From _Laravel_ 5.8 and on, the default is to use `bigIncrements` instead of `increments` for the `id` column on the `users` table. As such, the default for this package is to use the same convention for the `user_id` column on the `two_factor_auths` table. If this is not what you want, you can change this in the published config file by setting the "big_int" option to `false`.
94+
From _Laravel_ 5.8 and on, the default is to use `bigIncrements` instead of `increments` for the `id` column on the `users` table. As such, the default for this package is to use the same convention for the `user_id` column on the `two_factor_auths` table. If this is not what you want, you can modify the published migration files for this package.
9995

10096
5. Run the following *artisan* command to run the database migrations
10197
```
@@ -263,7 +259,9 @@ resolve(\MichaelDzjap\TwoFactorAuth\TwoFactorAuthManager)->extend('dummy', funct
263259
```php
264260
...
265261
'dummy' => [
262+
266263
'driver' => 'dummy',
264+
267265
],
268266
...
269267
```

src/Contracts/SMSToken.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ interface SMSToken
99
/**
1010
* Send a user a two-factor authentication token via SMS.
1111
*
12-
* @param User $user
12+
* @param \App\User $user
1313
* @return void
1414
*/
15-
public function sendSMSToken(User $user);
15+
public function sendSMSToken(User $user) : void;
1616
}

src/Contracts/TwoFactorProvider.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,32 @@ interface TwoFactorProvider
99
/**
1010
* Check if two-factor authentication is enabled for a user.
1111
*
12-
* @param User $user
12+
* @param \App\User $user
1313
* @return bool
1414
*/
1515
public function enabled(User $user);
1616

1717
/**
1818
* Register a user with this provider.
1919
*
20-
* @param User $user
20+
* @param \App\User $user
2121
* @return void
2222
*/
23-
public function register(User $user);
23+
public function register(User $user) : void;
2424

2525
/**
2626
* Unregister a user with this provider.
2727
*
28-
* @param User $user
28+
* @param \App\User $user
2929
* @return bool
3030
*/
3131
public function unregister(User $user);
3232

3333
/**
3434
* Determine if the token is valid.
3535
*
36-
* @param User $user
37-
* @param string $token
36+
* @param \App\User $user
37+
* @param string $token
3838
* @return bool
3939
*/
4040
public function verify(User $user, string $token);

src/Http/Controllers/ThrottlesTwoFactorAuths.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Foundation\Auth\ThrottlesLogins;
66
use Illuminate\Http\Request;
7+
use Illuminate\Support\Arr;
78
use Illuminate\Support\Str;
89

910
trait ThrottlesTwoFactorAuths
@@ -27,7 +28,7 @@ protected function hasTooManyTwoFactorAuthAttempts(Request $request)
2728
* @param \Illuminate\Http\Request $request
2829
* @return void
2930
*/
30-
protected function incrementTwoFactorAuthAttempts(Request $request)
31+
protected function incrementTwoFactorAuthAttempts(Request $request) : void
3132
{
3233
self::incrementLoginAttempts($request);
3334
}
@@ -54,7 +55,7 @@ protected function sendLockoutResponse(Request $request)
5455

5556
return redirect()->to('/login')
5657
->withInput(
57-
array_only($request->session()->get('two-factor:auth'), [$this->username(), 'remember'])
58+
Arr::only($request->session()->get('two-factor:auth'), [$this->username(), 'remember'])
5859
)
5960
->withErrors($errors);
6061
}
@@ -65,7 +66,7 @@ protected function sendLockoutResponse(Request $request)
6566
* @param \Illuminate\Http\Request $request
6667
* @return void
6768
*/
68-
protected function clearTwoFactorAuthAttempts(Request $request)
69+
protected function clearTwoFactorAuthAttempts(Request $request) : void
6970
{
7071
self::clearLoginAttempts($request);
7172
}
@@ -76,7 +77,7 @@ protected function clearTwoFactorAuthAttempts(Request $request)
7677
* @param \Illuminate\Http\Request $request
7778
* @return string
7879
*/
79-
protected function throttleKey(Request $request)
80+
protected function throttleKey(Request $request) : string
8081
{
8182
return Str::lower($request->session()->get('two-factor:auth')[$this->username()]).'|'.$request->ip();
8283
}

src/Http/Controllers/TwoFactorAuthenticatesUsers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected function sendKillTwoFactorAuthResponse(Request $request)
160160
*
161161
* @return string
162162
*/
163-
public function username()
163+
public function username() : string
164164
{
165165
return 'email';
166166
}

src/Providers/MessageBirdVerify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(Client $client)
3939
* @param \App\User $user
4040
* @return void
4141
*/
42-
public function register(User $user)
42+
public function register(User $user) : void
4343
{
4444
//
4545
}

src/TwoFactorAuthManager.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\Manager;
66
use MessageBird\Client;
7+
use MichaelDzjap\TwoFactorAuth\Contracts\TwoFactorProvider;
78
use MichaelDzjap\TwoFactorAuth\Providers\MessageBirdVerify;
89
use MichaelDzjap\TwoFactorAuth\Providers\NullProvider;
910

@@ -13,9 +14,9 @@ class TwoFactorAuthManager extends Manager
1314
* Get a driver instance.
1415
*
1516
* @param string $driver
16-
* @return mixed
17+
* @return \MichaelDzjap\TwoFactorAuth\Contracts\TwoFactorProvider
1718
*/
18-
public function provider($driver = null)
19+
public function provider(string $driver = null) : TwoFactorProvider
1920
{
2021
return $this->driver($driver);
2122
}
@@ -25,7 +26,7 @@ public function provider($driver = null)
2526
*
2627
* @return \MichaelDzjap\TwoFactorAuth\Contracts\TwoFactorProvider
2728
*/
28-
protected function createMessageBirdDriver()
29+
protected function createMessageBirdDriver() : TwoFactorProvider
2930
{
3031
return new MessageBirdVerify(
3132
new Client($this->app['config']['twofactor-auth.providers.messagebird.key'])
@@ -37,7 +38,7 @@ protected function createMessageBirdDriver()
3738
*
3839
* @return \MichaelDzjap\TwoFactorAuth\Contracts\TwoFactorProvider
3940
*/
40-
protected function createNullDriver()
41+
protected function createNullDriver() : TwoFactorProvider
4142
{
4243
return new NullProvider;
4344
}
@@ -47,7 +48,7 @@ protected function createNullDriver()
4748
*
4849
* @return string
4950
*/
50-
public function getDefaultDriver()
51+
public function getDefaultDriver() : string
5152
{
5253
return $this->app['config']['twofactor-auth.default'];
5354
}
@@ -58,7 +59,7 @@ public function getDefaultDriver()
5859
* @param string $name
5960
* @return void
6061
*/
61-
public function setDefaultDriver($name)
62+
public function setDefaultDriver(string $name) : void
6263
{
6364
$this->app['config']['twofactor-auth.default'] = $name;
6465
}

src/TwoFactorAuthServiceProvider.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TwoFactorAuthServiceProvider extends ServiceProvider
1313
*
1414
* @return void
1515
*/
16-
public function boot()
16+
public function boot() : void
1717
{
1818
$this->loadRoutesFrom(__DIR__.'/routes.php');
1919

@@ -39,7 +39,7 @@ public function boot()
3939
*
4040
* @return void
4141
*/
42-
public function register()
42+
public function register() : void
4343
{
4444
$this->mergeConfigFrom(
4545
__DIR__.'/config/twofactor-auth.php', 'twofactor-auth'
@@ -55,9 +55,11 @@ public function register()
5555
}
5656

5757
/**
58-
* Adds current timestamp prefix.
58+
* Publish this package's migration files
59+
*
60+
* @return void
5961
*/
60-
protected function publishMigrations()
62+
protected function publishMigrations() : void
6163
{
6264
$files = [
6365
'add_mobile_to_users_table.php',

src/TwoFactorAuthenticable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function setTwoFactorAuthId(string $id) : void
4343
/**
4444
* Get the two-factor auth id.
4545
*
46-
* @return string $id
46+
* @return string
4747
*/
4848
public function getTwoFactorAuthId() : string
4949
{

0 commit comments

Comments
 (0)