Skip to content

Commit 6f5a91c

Browse files
authored
Apply fixes from StyleCI
2 parents 4a71097 + 19df73d commit 6f5a91c

29 files changed

+367
-314
lines changed

config/device.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,34 @@
66
| Authorization Model
77
|--------------------------------------------------------------------------
88
|
9-
| If you would like to override the default device authorization model,
9+
| If you would like to override the default device authorization model,
1010
| you can do so within the section below.
1111
|
1212
*/
1313

1414
'authorization_model' => \BoxedCode\Laravel\Auth\Device\Models\DeviceAuthorization::class,
15-
15+
1616
/*
1717
|--------------------------------------------------------------------------
1818
| Lifetimes
1919
|--------------------------------------------------------------------------
2020
|
21-
| You can configure the lifetimes of various aspects of the package below,
21+
| You can configure the lifetimes of various aspects of the package below,
2222
| note that all lifetimes are specified in seconds.
2323
|
2424
*/
2525

2626
'lifetimes' => [
2727

2828
/*
29-
| Users can be periodically required to reauthorize their devices. By default,
30-
| device authorization are set to expire once a year. You can set this value to
29+
| Users can be periodically required to reauthorize their devices. By default,
30+
| device authorization are set to expire once a year. You can set this value to
3131
| false to prevent authorizations from expiring.
3232
*/
3333
'authorization' => env('DEVICE_AUTH_LIFETIME', 60 * 60 * 24 * 365),
3434

3535
/*
36-
| All authorization requests issued are only valid for a specific length
36+
| All authorization requests issued are only valid for a specific length
3737
| of time, you can set this here, by default this is set to one hour.
3838
*/
3939
'request' => env('DEVICE_AUTH_REQUEST_LIFETIME', 60 * 60),
@@ -56,13 +56,13 @@
5656
| Fingerprints
5757
|--------------------------------------------------------------------------
5858
|
59-
| Device fingerprints are created by hashing data from request data. We have
59+
| Device fingerprints are created by hashing data from request data. We have
6060
| set some sensible defaults below that will work for most cases.
6161
|
62-
| You can create further entropy by using a client side fingerprinting library
63-
| such as fingerprint.js and posting a '_fingerprint' field with your usual
64-
| authentication data. You will also need to uncomment the 'client_fingerprint'
65-
| entry below which will add the '_fingerprint' posted to the data collected
62+
| You can create further entropy by using a client side fingerprinting library
63+
| such as fingerprint.js and posting a '_fingerprint' field with your usual
64+
| authentication data. You will also need to uncomment the 'client_fingerprint'
65+
| entry below which will add the '_fingerprint' posted to the data collected
6666
| server-side and create an even stronger fingerprint for the device.
6767
|
6868
*/
@@ -75,12 +75,12 @@
7575
'server' => [
7676
'HTTP_USER_AGENT',
7777
'HTTP_ACCEPT_LANGUAGE',
78-
'HTTP_ACCEPT'
78+
'HTTP_ACCEPT',
7979
],
8080
'session' => [
8181
//'client_fingerprint'
82-
]
83-
]
82+
],
83+
],
8484

8585
],
8686

@@ -114,4 +114,4 @@
114114

115115
],
116116

117-
];
117+
];

migrations/2019_07_27_113423_device_authorizations.php

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

3-
use Illuminate\Support\Facades\Schema;
4-
use Illuminate\Database\Schema\Blueprint;
53
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Support\Facades\Schema;
65

76
class DeviceAuthorizations extends Migration
87
{
@@ -13,7 +12,7 @@ class DeviceAuthorizations extends Migration
1312
*/
1413
public function up()
1514
{
16-
Schema::create('device_authorizations', function($table) {
15+
Schema::create('device_authorizations', function ($table) {
1716
$table->string('uuid')->primary();
1817
$table->text('fingerprint');
1918
$table->string('browser');

src/AuthBroker.php

Lines changed: 63 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace BoxedCode\Laravel\Auth\Device;
44

5-
use BoxedCode\Laravel\Auth\Device\AuthBrokerResponse;
65
use BoxedCode\Laravel\Auth\Device\Contracts\AuthBroker as BrokerContract;
76
use BoxedCode\Laravel\Auth\Device\Contracts\HasDeviceAuthorizations;
87
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
@@ -13,21 +12,21 @@ class AuthBroker implements BrokerContract
1312
{
1413
/**
1514
* The configuration array.
16-
*
15+
*
1716
* @var array
1817
*/
1918
protected $config;
2019

2120
/**
2221
* The event dispatcher instance.
23-
*
22+
*
2423
* @var \Illuminate\Contracts\Events\Dispatcher
2524
*/
2625
protected $events;
2726

2827
/**
2928
* Create a new broker instance.
30-
*
29+
*
3130
* @param array $config
3231
*/
3332
public function __construct(array $config = [])
@@ -37,11 +36,12 @@ public function __construct(array $config = [])
3736

3837
/**
3938
* Send a challenge to the user with a verification link.
40-
*
41-
* @param \BoxedCode\Laravel\Auth\Device\Contracts\HasDeviceAuthorizations $user
42-
* @param string $fingerprint
43-
* @param string $browser
44-
* @param string $ip
39+
*
40+
* @param \BoxedCode\Laravel\Auth\Device\Contracts\HasDeviceAuthorizations $user
41+
* @param string $fingerprint
42+
* @param string $browser
43+
* @param string $ip
44+
*
4545
* @return \BoxedCode\Laravel\Auth\Device\AuthBrokerResponse
4646
*/
4747
public function challenge(HasDeviceAuthorizations $user, $fingerprint, $browser, $ip)
@@ -57,29 +57,30 @@ public function challenge(HasDeviceAuthorizations $user, $fingerprint, $browser,
5757
// Check that the device is not already authorized.
5858
if ($authorization = $this->findExistingVerifiedAuthorization($user, $fingerprint)) {
5959
return $this->respond(static::DEVICE_ALREADY_AUTHORIZED, [
60-
'authorization' => $authorization
60+
'authorization' => $authorization,
6161
]);
6262
}
6363

6464
// Create a new authorization.
6565
$authorization = $this->newAuthorization($user, $fingerprint, $browser, $ip);
6666

67-
// Send the request and verification token
67+
// Send the request and verification token
6868
$user->notify(new $this->config['notification']($authorization->verify_token, $browser, $ip));
6969

7070
$this->event(new Events\Challenged($authorization));
7171

7272
return $this->respond(static::USER_CHALLENGED, [
73-
'authorization' => $authorization
73+
'authorization' => $authorization,
7474
]);
75-
}
75+
}
7676

7777
/**
7878
* Verify the challenge and authorize the user.
79-
*
80-
* @param \BoxedCode\Laravel\Auth\Device\Contracts\HasDeviceAuthorizations $user
81-
* @param string $fingerprint
82-
* @param string $token
79+
*
80+
* @param \BoxedCode\Laravel\Auth\Device\Contracts\HasDeviceAuthorizations $user
81+
* @param string $fingerprint
82+
* @param string $token
83+
*
8384
* @return \BoxedCode\Laravel\Auth\Device\AuthBrokerResponse
8485
*/
8586
public function verifyAndAuthorize(HasDeviceAuthorizations $user, $fingerprint, $token)
@@ -110,17 +111,18 @@ public function verifyAndAuthorize(HasDeviceAuthorizations $user, $fingerprint,
110111
$this->event(new Events\Authorized($authorization));
111112

112113
return $this->respond(static::DEVICE_AUTHORIZED, [
113-
'authorization' => $authorization
114+
'authorization' => $authorization,
114115
]);
115116
}
116117

117118
/**
118119
* Authorize a device without verification.
119-
*
120-
* @param \BoxedCode\Laravel\Auth\Device\Contracts\HasDeviceAuthorizations $user
121-
* @param string $fingerprint
122-
* @param string $browser
123-
* @param string $ip
120+
*
121+
* @param \BoxedCode\Laravel\Auth\Device\Contracts\HasDeviceAuthorizations $user
122+
* @param string $fingerprint
123+
* @param string $browser
124+
* @param string $ip
125+
*
124126
* @return \BoxedCode\Laravel\Auth\Device\AuthBrokerResponse
125127
*/
126128
public function authorize(HasDeviceAuthorizations $user, $fingerprint, $browser, $ip)
@@ -133,23 +135,27 @@ public function authorize(HasDeviceAuthorizations $user, $fingerprint, $browser,
133135
// Check the device is not already verified.
134136
if ($authorization = $this->findExistingVerifiedAuthorization($user, $fingerprint)) {
135137
return $this->respond(static::DEVICE_ALREADY_AUTHORIZED, [
136-
'authorization' => $authorization
138+
'authorization' => $authorization,
137139
]);
138140
}
139141

140142
// Create a new verified authorization.
141143
$authorization = $this->newAuthorization(
142-
$user, $fingerprint, $browser, $ip, $verified_at = now()
144+
$user,
145+
$fingerprint,
146+
$browser,
147+
$ip,
148+
$verified_at = now()
143149
);
144150

145151
return $this->respond(static::DEVICE_AUTHORIZED, [
146-
'authorization' => $authorization
152+
'authorization' => $authorization,
147153
]);
148154
}
149155

150156
/**
151157
* Set the event dispatcher.
152-
*
158+
*
153159
* @param EventDispatcher $events
154160
*/
155161
public function setEventDispatcher(EventDispatcher $events)
@@ -161,7 +167,7 @@ public function setEventDispatcher(EventDispatcher $events)
161167

162168
/**
163169
* Get the event dispatcher.
164-
*
170+
*
165171
* @return \Illuminate\Contracts\Events\Dispatcher
166172
*/
167173
public function getEventDispatcher()
@@ -178,15 +184,15 @@ protected function event()
178184
{
179185
if ($this->events) {
180186
call_user_func_array(
181-
[$this->events, 'dispatch'],
187+
[$this->events, 'dispatch'],
182188
func_get_args()
183189
);
184190
}
185191
}
186192

187193
/**
188194
* Generate a new verification token.
189-
*
195+
*
190196
* @return string
191197
*/
192198
protected function newVerifyToken()
@@ -196,40 +202,43 @@ protected function newVerifyToken()
196202

197203
/**
198204
* Create a new authorization record.
199-
*
200-
* @param \BoxedCode\Laravel\Auth\Device\Contracts\HasDeviceAuthorizations $user
201-
* @param string $fingerprint
202-
* @param string $browser
203-
* @param string $ip
204-
* @param DateTime|null $verified_at
205+
*
206+
* @param \BoxedCode\Laravel\Auth\Device\Contracts\HasDeviceAuthorizations $user
207+
* @param string $fingerprint
208+
* @param string $browser
209+
* @param string $ip
210+
* @param DateTime|null $verified_at
211+
*
205212
* @return \BoxedCode\Laravel\Auth\Device\Contracts\DeviceAuthorization
206213
*/
207-
protected function newAuthorization(HasDeviceAuthorizations $user,
208-
$fingerprint,
209-
$browser,
210-
$ip,
211-
$verified_at = null
214+
protected function newAuthorization(
215+
HasDeviceAuthorizations $user,
216+
$fingerprint,
217+
$browser,
218+
$ip,
219+
$verified_at = null
212220
) {
213221
$algorithm = $this->config['fingerprints']['algorithm'];
214222

215223
$fingerprintHash = hash($algorithm, $fingerprint);
216224

217225
// Create the authorizations
218226
return $user->deviceAuthorizations()->create([
219-
'uuid' => Str::uuid(),
220-
'fingerprint' => $fingerprintHash,
221-
'browser' => $browser,
222-
'ip' => $ip,
227+
'uuid' => Str::uuid(),
228+
'fingerprint' => $fingerprintHash,
229+
'browser' => $browser,
230+
'ip' => $ip,
223231
'verify_token' => $token = $this->newVerifyToken(),
224-
'verified_at' => $verified_at,
232+
'verified_at' => $verified_at,
225233
]);
226234
}
227235

228236
/**
229237
* Find an existing verified verification by fingerprint.
230-
*
231-
* @param \BoxedCode\Laravel\Auth\Device\Contracts\HasDeviceAuthorizations $user
232-
* @param string $fingerprint
238+
*
239+
* @param \BoxedCode\Laravel\Auth\Device\Contracts\HasDeviceAuthorizations $user
240+
* @param string $fingerprint
241+
*
233242
* @return \BoxedCode\Laravel\Auth\Device\Contracts\DeviceAuthorization
234243
*/
235244
protected function findExistingVerifiedAuthorization(HasDeviceAuthorizations $user, $fingerprint)
@@ -247,13 +256,14 @@ protected function findExistingVerifiedAuthorization(HasDeviceAuthorizations $us
247256

248257
/**
249258
* Create a new broker response instance.
250-
*
251-
* @param string $outcome
252-
* @param array $payload
259+
*
260+
* @param string $outcome
261+
* @param array $payload
262+
*
253263
* @return \BoxedCode\Laravel\Auth\Device\AuthBrokerResponse
254264
*/
255265
protected function respond($outcome, array $payload = [])
256266
{
257267
return new AuthBrokerResponse($outcome, $payload);
258268
}
259-
}
269+
}

0 commit comments

Comments
 (0)