Failed Conditions
Push — master ( 7f2d83...323120 )
by Florent
05:07
created

MaxAgeParameterAccountChecker::check()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.3222
c 0
b 0
f 0
cc 5
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\UserAccount;
15
16
use OAuth2Framework\Component\AuthorizationEndpoint\AuthorizationRequest\AuthorizationRequest;
17
use OAuth2Framework\Component\AuthorizationEndpoint\Exception\RedirectToLoginPageException;
18
19
final class MaxAgeParameterAccountChecker implements UserAccountChecker
20
{
21
    public function check(AuthorizationRequest $authorization): void
22
    {
23
        switch (true) {
24
            case $authorization->hasQueryParam('max_age'):
25
                $max_age = (int) $authorization->getQueryParam('max_age');
26
27
                break;
28
            case $authorization->getClient()->has('default_max_age'):
29
                $max_age = (int) $authorization->getClient()->get('default_max_age');
30
31
                break;
32
            default:
33
                return;
34
        }
35
36
        if (null === $authorization->getUserAccount()->getLastLoginAt() || \time() - $authorization->getUserAccount()->getLastLoginAt() > $max_age) {
37
            throw new RedirectToLoginPageException($authorization);
38
        }
39
    }
40
}
41