1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Flipbox\OAuth2\Client\Provider; |
4
|
|
|
|
5
|
|
|
use Flipbox\OAuth2\Client\Provider\Exception\GuardianIdentityProviderException; |
6
|
|
|
use League\OAuth2\Client\Provider\AbstractProvider; |
7
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
8
|
|
|
use League\OAuth2\Client\Tool\BearerAuthorizationTrait; |
9
|
|
|
use Psr\Http\Message\ResponseInterface; |
10
|
|
|
|
11
|
|
|
abstract class AbstractGuardian extends AbstractProvider |
12
|
|
|
{ |
13
|
|
|
use BearerAuthorizationTrait; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @inheritdoc |
17
|
|
|
*/ |
18
|
6 |
|
protected function getScopeSeparator() |
19
|
|
|
{ |
20
|
6 |
|
return ' '; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @inheritdoc |
25
|
|
|
*/ |
26
|
6 |
|
protected function getAuthorizationParameters(array $options) |
27
|
|
|
{ |
28
|
6 |
|
return array_merge( |
29
|
6 |
|
parent::getAuthorizationParameters($options), |
30
|
|
|
[ |
31
|
6 |
|
'client_secret' => $this->clientSecret |
32
|
2 |
|
] |
33
|
2 |
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @inheritdoc |
38
|
|
|
*/ |
39
|
12 |
|
protected function getDefaultHeaders() |
40
|
|
|
{ |
41
|
|
|
return [ |
42
|
8 |
|
'accept' => 'application/json' |
43
|
4 |
|
]; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Returns the request body for requesting an access token. |
48
|
|
|
* |
49
|
|
|
* @param array $params |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
12 |
|
protected function getAccessTokenBody(array $params) |
53
|
|
|
{ |
54
|
12 |
|
return json_encode(array_filter($params)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Builds request options used for requesting an access token. |
59
|
|
|
* |
60
|
|
|
* @param array $params |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
12 |
|
protected function getAccessTokenOptions(array $params) |
64
|
|
|
{ |
65
|
12 |
|
$option = array_merge( |
66
|
12 |
|
parent::getAccessTokenOptions($params), |
67
|
|
|
[ |
68
|
8 |
|
'headers' => [ |
69
|
|
|
'content-type' => 'application/json' |
70
|
4 |
|
] |
71
|
4 |
|
] |
72
|
4 |
|
); |
73
|
|
|
|
74
|
12 |
|
return $option; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @inheritdoc |
79
|
|
|
*/ |
80
|
12 |
|
protected function checkResponse(ResponseInterface $response, $data) |
81
|
|
|
{ |
82
|
12 |
|
if ($response->getStatusCode() >= 400) { |
83
|
3 |
|
throw GuardianIdentityProviderException::clientException($response, $data); |
|
|
|
|
84
|
9 |
|
} elseif (isset($data['error'])) { |
85
|
3 |
|
throw GuardianIdentityProviderException::oauthException($response, $data); |
|
|
|
|
86
|
|
|
} |
87
|
6 |
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @inheritdoc |
91
|
|
|
*/ |
92
|
3 |
|
protected function createResourceOwner(array $response, AccessToken $token) |
93
|
|
|
{ |
94
|
3 |
|
return new GuardianResourceOwner($response); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.