22
33namespace BoxedCode \Laravel \Auth \Device ;
44
5- use BoxedCode \Laravel \Auth \Device \AuthBrokerResponse ;
65use BoxedCode \Laravel \Auth \Device \Contracts \AuthBroker as BrokerContract ;
76use BoxedCode \Laravel \Auth \Device \Contracts \HasDeviceAuthorizations ;
87use 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