1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: Alexandre |
5
|
|
|
* Date: 18/02/2018 |
6
|
|
|
* Time: 18:08 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace OAuth2\Flows; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use OAuth2\Endpoints\AuthorizationEndpoint; |
13
|
|
|
use OAuth2\Endpoints\TokenEndpoint; |
14
|
|
|
use OAuth2\GrantTypes\AbstractGrantType; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
class ImplicitFlow extends AbstractGrantType implements FlowInterface |
18
|
|
|
{ |
19
|
|
|
public function getResponseTypes(): array |
20
|
|
|
{ |
21
|
|
|
return ['token']; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function verifyAuthorizationRequest(AuthorizationEndpoint $authorizationEndpoint, array $requestData) |
25
|
|
|
{ |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function handleAuthorizationRequest(AuthorizationEndpoint $authorizationEndpoint, array $requestData): array |
29
|
|
|
{ |
30
|
|
|
$data = $this->issueAccessToken( |
31
|
|
|
implode(' ', $authorizationEndpoint->getScopes()), |
32
|
|
|
$authorizationEndpoint->getClient()->getIdentifier(), |
33
|
|
|
$authorizationEndpoint->getResourceOwner()->getIdentifier() |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
if (!$this->arrayEqual($authorizationEndpoint->getScopes(), $requestData['scope'] ?? null)) { |
37
|
|
|
$data['scope'] = implode(' ', $authorizationEndpoint->getScopes()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
return $data; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function getDefaultResponseMode(): string |
44
|
|
|
{ |
45
|
|
|
return 'fragment'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getUnsupportedResponseModes(): array |
49
|
|
|
{ |
50
|
|
|
return ['query']; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getGrantTypes(): array |
54
|
|
|
{ |
55
|
|
|
return []; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function handleAccessTokenRequest(TokenEndpoint $tokenEndpoint, array $requestData): array |
59
|
|
|
{ |
60
|
|
|
throw new \BadMethodCallException(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private function arrayEqual($a, $b) |
64
|
|
|
{ |
65
|
|
|
return ( |
66
|
|
|
is_array($a) |
67
|
|
|
&& is_array($b) |
68
|
|
|
&& count($a) == count($b) |
69
|
|
|
&& array_diff($a, $b) === array_diff($b, $a) |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
} |