Skip to content

Commit 1625f59

Browse files
Merge pull request #67 from Laragear/fix/key-cast
[1.x] Should fix unnecessary cast
2 parents cf00ad7 + 3356ab8 commit 1625f59

12 files changed

Lines changed: 72 additions & 73 deletions

config/two-factor.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414

1515
'cache' => [
16-
'store' => null,
16+
'store' => null,
1717
'prefix' => '2fa.code',
1818
],
1919

@@ -30,8 +30,8 @@
3030

3131
'recovery' => [
3232
'enabled' => true,
33-
'codes' => 10,
34-
'length' => 8,
33+
'codes' => 10,
34+
'length' => 8,
3535
],
3636

3737
/*
@@ -46,9 +46,9 @@
4646
*/
4747

4848
'safe_devices' => [
49-
'enabled' => false,
50-
'cookie' => '_2fa_remember',
51-
'max_devices' => 3,
49+
'enabled' => false,
50+
'cookie' => '_2fa_remember',
51+
'max_devices' => 3,
5252
'expiration_days' => 14,
5353
],
5454

@@ -118,9 +118,9 @@
118118
'issuer' => env('OTP_TOTP_ISSUER'),
119119

120120
'totp' => [
121-
'digits' => 6,
122-
'seconds' => 30,
123-
'window' => 1,
121+
'digits' => 6,
122+
'seconds' => 30,
123+
'window' => 1,
124124
'algorithm' => 'sha1',
125125
],
126126

@@ -136,7 +136,7 @@
136136
*/
137137

138138
'qr_code' => [
139-
'size' => 400,
139+
'size' => 400,
140140
'margin' => 4,
141141
],
142142
];

lang/en/messages.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
<?php
22

33
return [
4-
'title' => 'Two-Factor Authentication',
4+
'title' => 'Two-Factor Authentication',
55
'required' => 'Two-Factor Authentication is required.',
6-
'back' => 'Go back',
6+
'back' => 'Go back',
77
'continue' => 'To continue, open up your Authenticator app and issue your 2FA code.',
8-
'enable' => 'You need to enable Two-Factor Authentication.',
8+
'enable' => 'You need to enable Two-Factor Authentication.',
99

1010
'success' => 'The 2FA code has been validated successfully.',
1111

1212
'fail_confirm' => 'The code to activate Two-Factor Authentication is invalid.',
13-
'enabled' => 'Two-Factor Authentication has been enabled for your account.',
14-
'disabled' => 'Two-Factor Authentication has been disabled for your account.',
13+
'enabled' => 'Two-Factor Authentication has been enabled for your account.',
14+
'disabled' => 'Two-Factor Authentication has been disabled for your account.',
1515

1616
'safe_device' => 'We won\'t ask you for Two-Factor Authentication codes in this device for some time.',
1717

18-
'confirm' => 'Confirm code',
18+
'confirm' => 'Confirm code',
1919
'switch_on' => 'Go to enable Two-Factor Authentication.',
2020

2121
'recovery_code' => [
22-
'used' => 'You have used a Recovery Code. Remember to regenerate them if you have used almost all.',
23-
'depleted' => 'You have used all your Recovery Codes. Please use alternate authentication methods to continue.',
22+
'used' => 'You have used a Recovery Code. Remember to regenerate them if you have used almost all.',
23+
'depleted' => 'You have used all your Recovery Codes. Please use alternate authentication methods to continue.',
2424
'generated' => 'You have generated a new set of Recovery Codes. Any previous set of codes have been invalidated.',
2525
],
2626
];

src/Models/Concerns/HandlesRecoveryCodes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function containsUnusedRecoveryCodes(): bool
3737
protected function getUnusedRecoveryCodeIndex(string $code): int|null|bool
3838
{
3939
return $this->recovery_codes?->search([
40-
'code' => $code,
40+
'code' => $code,
4141
'used_at' => null,
4242
], true);
4343
}
@@ -57,7 +57,7 @@ public function setRecoveryCodeAsUsed(string $code): bool
5757
}
5858

5959
$this->recovery_codes = $this->recovery_codes->put($index, [
60-
'code' => $code,
60+
'code' => $code,
6161
'used_at' => now(),
6262
]);
6363

@@ -90,7 +90,7 @@ public static function generateRecoveryCodes(int $amount, int $length): Collecti
9090

9191
return Collection::times($amount, static function (int $iteration) use ($generator, $amount, $length): array {
9292
return [
93-
'code' => $generator($length, $iteration, $amount),
93+
'code' => $generator($length, $iteration, $amount),
9494
'used_at' => null,
9595
];
9696
});

src/Models/Concerns/SerializesSharedSecret.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public function toUri(): string
2929
?: config('app.name')
3030
?: throw new InvalidArgumentException('The TOTP issuer cannot be empty.');
3131
$query = http_build_query([
32-
'issuer' => $issuer,
33-
'label' => $this->attributes['label'],
34-
'secret' => $this->shared_secret,
32+
'issuer' => $issuer,
33+
'label' => $this->attributes['label'],
34+
'secret' => $this->shared_secret,
3535
'algorithm' => strtoupper($this->attributes['algorithm']),
36-
'digits' => $this->attributes['digits'],
36+
'digits' => $this->attributes['digits'],
3737
], '', '&', PHP_QUERY_RFC3986);
3838

3939
return 'otpauth://totp/'.rawurlencode($issuer).'%3A'.$this->attributes['label']."?$query";

src/Models/TwoFactorAuthentication.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,13 @@ class TwoFactorAuthentication extends Model implements TwoFactorTotp
5151
* @var array
5252
*/
5353
protected $casts = [
54-
'shared_secret' => 'encrypted',
55-
'authenticatable_id' => 'int',
56-
'digits' => 'int',
57-
'seconds' => 'int',
58-
'window' => 'int',
59-
'recovery_codes' => 'encrypted:collection',
60-
'safe_devices' => 'collection',
61-
'enabled_at' => 'datetime',
54+
'shared_secret' => 'encrypted',
55+
'digits' => 'int',
56+
'seconds' => 'int',
57+
'window' => 'int',
58+
'recovery_codes' => 'encrypted:collection',
59+
'safe_devices' => 'collection',
60+
'enabled_at' => 'datetime',
6261
'recovery_codes_generated_at' => 'datetime',
6362
];
6463

src/TwoFactorAuthentication.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ public function addSafeDevice(Request $request): string
251251
$this->twoFactorAuth->safe_devices = $this->safeDevices()
252252
->push([
253253
'2fa_remember' => $token = $this->generateTwoFactorRemember(),
254-
'ip' => $request->ip(),
255-
'added_at' => $this->freshTimestamp()->getTimestamp(),
254+
'ip' => $request->ip(),
255+
'added_at' => $this->freshTimestamp()->getTimestamp(),
256256
])
257257
->sortByDesc('added_at') // Ensure the last is the first, so we can slice it.
258258
->slice(0, config('two-factor.safe_devices.max_devices', 3))

tests/CreatesTwoFactorUser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ trait CreatesTwoFactorUser
1313
protected function createTwoFactorUser(): void
1414
{
1515
$this->user = UserTwoFactorStub::create([
16-
'name' => 'foo',
17-
'email' => 'foo@test.com',
16+
'name' => 'foo',
17+
'email' => 'foo@test.com',
1818
'password' => UserStub::PASSWORD_SECRET,
1919
]);
2020

tests/Eloquent/TwoFactorAuthenticationTest.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class TwoFactorAuthenticationTest extends TestCase
2222
public function test_returns_authenticatable(): void
2323
{
2424
$user = UserTwoFactorStub::create([
25-
'name' => 'foo',
26-
'email' => 'foo@test.com',
25+
'name' => 'foo',
26+
'email' => 'foo@test.com',
2727
'password' => UserStub::PASSWORD_SECRET,
2828
]);
2929

@@ -65,7 +65,7 @@ public function test_flushes_authentication(): void
6565
->withRecovery()->withSafeDevices()
6666
->create([
6767
'authenticatable_type' => 'test',
68-
'authenticatable_id' => 9,
68+
'authenticatable_id' => 9,
6969
]);
7070

7171
static::assertNotNull($old = $tfa->shared_secret);
@@ -142,7 +142,7 @@ public function test_validate_code(): void
142142
{
143143
$tfa = TwoFactorAuthentication::factory()->withRecovery()->withSafeDevices()->make([
144144
'shared_secret' => static::SECRET,
145-
'window' => 0,
145+
'window' => 0,
146146
]);
147147

148148
$this->travelTo(Date::create(2020, 1, 1, 20, 30, 0));
@@ -161,7 +161,7 @@ public function test_validate_code_with_window(): void
161161
{
162162
$tfa = TwoFactorAuthentication::factory()->withRecovery()->withSafeDevices()->make([
163163
'shared_secret' => static::SECRET,
164-
'window' => 1,
164+
'window' => 1,
165165
]);
166166

167167
$this->travelTo(Date::create(2020, 1, 1, 20, 30, 0));
@@ -201,7 +201,7 @@ public function test_contains_unused_recovery_codes(): void
201201
$tfa = TwoFactorAuthentication::factory()->withRecovery()->withSafeDevices()->make([
202202
'recovery_codes' => collect([
203203
[
204-
'code' => '2G5oP36',
204+
'code' => '2G5oP36',
205205
'used_at' => 'anything not null',
206206
],
207207
]),
@@ -252,10 +252,10 @@ public function test_serializes_to_uri(): void
252252
$this->app->make('config')->set('two-factor.issuer', 'quz');
253253

254254
$tfa = TwoFactorAuthentication::factory()->withRecovery()->withSafeDevices()->make([
255-
'label' => 'test@foo.com',
255+
'label' => 'test@foo.com',
256256
'shared_secret' => static::SECRET,
257-
'algorithm' => 'sHa256',
258-
'digits' => 14,
257+
'algorithm' => 'sHa256',
258+
'digits' => 14,
259259
]);
260260

261261
$uri = 'otpauth://totp/quz%3Atest@foo.com?issuer=quz&label=test%40foo.com&secret=KS72XBTN5PEBGX2IWBMVW44LXHPAQ7L3&algorithm=SHA256&digits=14';
@@ -268,10 +268,10 @@ public function test_serializes_to_qr_and_renders_to_qr(): void
268268
$this->app->make('config')->set('two-factor.issuer', 'quz');
269269

270270
$tfa = TwoFactorAuthentication::factory()->withRecovery()->withSafeDevices()->make([
271-
'label' => 'test@foo.com',
271+
'label' => 'test@foo.com',
272272
'shared_secret' => static::SECRET,
273-
'algorithm' => 'sHa256',
274-
'digits' => 14,
273+
'algorithm' => 'sHa256',
274+
'digits' => 14,
275275
]);
276276

277277
static::assertStringEqualsFile(__DIR__.'/../Stubs/QrStub.svg', $tfa->toQr());
@@ -289,10 +289,10 @@ public function test_serializes_to_qr_and_renders_to_qr_with_custom_values(): vo
289289
]);
290290

291291
$tfa = TwoFactorAuthentication::factory()->withRecovery()->withSafeDevices()->make([
292-
'label' => 'test@foo.com',
292+
'label' => 'test@foo.com',
293293
'shared_secret' => static::SECRET,
294-
'algorithm' => 'sHa256',
295-
'digits' => 14,
294+
'algorithm' => 'sHa256',
295+
'digits' => 14,
296296
]);
297297

298298
static::assertStringEqualsFile(__DIR__.'/../Stubs/CustomQrStub.svg', $tfa->toQr());
@@ -304,10 +304,10 @@ public function test_serializes_uri_to_json(): void
304304
$this->app->make('config')->set('two-factor.issuer', 'quz');
305305

306306
$tfa = TwoFactorAuthentication::factory()->withRecovery()->withSafeDevices()->make([
307-
'label' => 'test@foo.com',
307+
'label' => 'test@foo.com',
308308
'shared_secret' => static::SECRET,
309-
'algorithm' => 'sHa256',
310-
'digits' => 14,
309+
'algorithm' => 'sHa256',
310+
'digits' => 14,
311311
]);
312312

313313
$uri = '"otpauth:\/\/totp\/quz%3Atest@foo.com?issuer=quz&label=test%40foo.com&secret=KS72XBTN5PEBGX2IWBMVW44LXHPAQ7L3&algorithm=SHA256&digits=14"';
@@ -319,10 +319,10 @@ public function test_serializes_uri_to_json(): void
319319
public function test_uses_app_name_as_issuer(): void
320320
{
321321
$tfa = TwoFactorAuthentication::factory()->withRecovery()->withSafeDevices()->make([
322-
'label' => 'test@foo.com',
322+
'label' => 'test@foo.com',
323323
'shared_secret' => static::SECRET,
324-
'algorithm' => 'sHa256',
325-
'digits' => 14,
324+
'algorithm' => 'sHa256',
325+
'digits' => 14,
326326
]);
327327

328328
$uri = 'otpauth://totp/Laravel%3Atest@foo.com?issuer=Laravel&label=test%40foo.com&secret=KS72XBTN5PEBGX2IWBMVW44LXHPAQ7L3&algorithm=SHA256&digits=14';
@@ -335,10 +335,10 @@ public function test_changes_issuer(): void
335335
$this->app->make('config')->set('two-factor.issuer', 'foo bar');
336336

337337
$tfa = TwoFactorAuthentication::factory()->withRecovery()->withSafeDevices()->make([
338-
'label' => 'test@foo.com',
338+
'label' => 'test@foo.com',
339339
'shared_secret' => static::SECRET,
340-
'algorithm' => 'sHa256',
341-
'digits' => 14,
340+
'algorithm' => 'sHa256',
341+
'digits' => 14,
342342
]);
343343

344344
$uri = 'otpauth://totp/foo%20bar%3Atest@foo.com?issuer=foo%20bar&label=test%40foo.com&secret=KS72XBTN5PEBGX2IWBMVW44LXHPAQ7L3&algorithm=SHA256&digits=14';
@@ -352,10 +352,10 @@ public function test_throws_exception_when_issuer_is_empty(): void
352352
$this->app->make('config')->set('two-factor.issuer', '');
353353

354354
$tfa = TwoFactorAuthentication::factory()->withRecovery()->withSafeDevices()->make([
355-
'label' => 'test@foo.com',
355+
'label' => 'test@foo.com',
356356
'shared_secret' => static::SECRET,
357-
'algorithm' => 'sHa256',
358-
'digits' => 14,
357+
'algorithm' => 'sHa256',
358+
'digits' => 14,
359359
]);
360360

361361
$this->expectException(InvalidArgumentException::class);

tests/Events/EventsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function test_fires_two_factor_recovery_codes_depleted(): void
5858

5959
$this->user->twoFactorAuth->recovery_codes = Collection::times(1, static function () use ($code): array {
6060
return [
61-
'code' => $code,
61+
'code' => $code,
6262
'used_at' => null,
6363
];
6464
});

tests/Http/Middleware/ConfirmTwoFactorEnabledTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public function test_guest_cant_access(): void
4545
public function test_continues_if_user_is_not_2fa_instance(): void
4646
{
4747
$this->actingAs(UserStub::create([
48-
'name' => 'test',
49-
'email' => 'bar@test.com',
48+
'name' => 'test',
49+
'email' => 'bar@test.com',
5050
'password' => UserStub::PASSWORD_SECRET,
5151
]));
5252

0 commit comments

Comments
 (0)