Failed Conditions
Push — master ( 7c3864...930f9b )
by Florent
14:15
created

isAuthenticationNeeded()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 4
nc 5
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Component\AuthorizationEndpoint\User;
15
16
use OAuth2Framework\Component\AuthorizationEndpoint\AuthorizationRequest\AuthorizationRequest;
17
18
final class MaxAgeParameterAuthenticationChecker implements UserAuthenticationChecker
19
{
20
    public function isAuthenticationNeeded(AuthorizationRequest $authorization): bool
21
    {
22
        switch (true) {
23
            case $authorization->hasQueryParam('max_age'):
24
                $max_age = (int) $authorization->getQueryParam('max_age');
25
26
                break;
27
            case $authorization->getClient()->has('default_max_age'):
28
                $max_age = (int) $authorization->getClient()->get('default_max_age');
29
30
                break;
31
            default:
32
                return false;
33
        }
34
35
        return null === $authorization->getUser()->getLastLoginAt() || \time() - $authorization->getUser()->getLastLoginAt() > $max_age;
36
    }
37
}
38