Passed
Push — master ( 6fa43b...67ed79 )
by Marco Aurélio
03:25
created

CognitoUserProvider::retrieveByCredentials()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 2
b 0
f 0
nc 3
nop 1
dl 0
loc 21
ccs 7
cts 7
cp 1
crap 3
rs 10
1
<?php declare(strict_types=1);
2
3
namespace CustomerGauge\Cognito;
4
5
use CustomerGauge\Cognito\Parsers\AccessTokenParser;
6
use CustomerGauge\Cognito\Parsers\ClientAppParser;
7
use Exception;
8
use Illuminate\Contracts\Auth\Authenticatable;
9
use Illuminate\Contracts\Auth\UserProvider;
10
11
final class CognitoUserProvider implements UserProvider
12
{
13
    private $clientAppParser;
14
15
    private $accessTokenParser;
16
17 3
    public function __construct(ClientAppParser $clientAppParser, AccessTokenParser $accessTokenParser)
18
    {
19 3
        $this->clientAppParser = $clientAppParser;
20 3
        $this->accessTokenParser = $accessTokenParser;
21 3
    }
22
23 3
    public function retrieveByCredentials(array $credentials)
24
    {
25 3
        $token = $credentials['cognito_token'];
26
27
        try {
28 3
            return $this->clientAppParser->parse($token);
29 2
        } catch (Exception $e) {
30
            // If we cannot parse the token, that probably means the token is either invalid or
31
            // it might be an access token. We'll try to validate it as an access token next
32
            // and if that fails, we'll finally return null.
33
        }
34
35
        try {
36 2
            return $this->accessTokenParser->parse($token);
37 1
        } catch (Exception $e) {
38
            // The Laravel Authenticate Middleware implements the Chain Of Responsibility Pattern.
39
            //  We need to return null and let the next Guard try to authenticate. If all Guards
40
            // return null, then the middleware throws an AuthenticationException.
41
        }
42
43 1
        return null;
44
    }
45
46
    /** @phpstan ignore */
47
    public function validateCredentials(Authenticatable $user, array $credentials)
48
    {
49
    }
50
51
    /** @phpstan ignore */
52
    public function retrieveById($identifier)
53
    {
54
    }
55
56
    /** @phpstan ignore */
57
    public function retrieveByToken($identifier, $token)
58
    {
59
    }
60
61
    /** @phpstan ignore */
62
    public function updateRememberToken(Authenticatable $user, $token)
63
    {
64
    }
65
}
66