Conditions | 6 |
Paths | 6 |
Total Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 9.6594 |
Changes | 0 |
1 | <?php |
||
21 | 1 | public function handle($request, Closure $next) |
|
22 | { |
||
23 | /** @var Authenticator $authenticator */ |
||
24 | 1 | $authenticator = app(Authenticator::class)->boot($request); |
|
25 | 1 | $cookieResult = $authenticator->hasValidCookieToken(); |
|
26 | 1 | $authResult = $authenticator->isAuthenticated(); |
|
27 | |||
28 | /** @var Response $response */ |
||
29 | 1 | $response = $next($request); |
|
30 | |||
31 | 1 | if (false === $cookieResult && true === $authResult) { |
|
32 | $cookieName = config('google2fa.cookie_name') ?? 'google2fa_token'; |
||
33 | $lifetime = (int)(config('google2fa.cookie_lifetime') ?? 8035200); |
||
34 | $lifetime = $lifetime > 8035200 ? 8035200 : $lifetime; |
||
35 | $token = $authenticator->sessionGet(Constants::SESSION_TOKEN); |
||
36 | $response->withCookie(cookie()->make($cookieName, $token, $lifetime / 60)); |
||
37 | } |
||
38 | |||
39 | 1 | if (true === $cookieResult || true === $authResult) { |
|
40 | return $response; |
||
41 | } |
||
42 | |||
43 | 1 | $authenticator->cleanupTokens(); |
|
44 | |||
45 | return $authenticator->makeRequestOneTimePasswordResponse(); |
||
46 | } |
||
47 | } |
||
48 |