|
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
|
|
|
|