1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Flipbox\OAuth2\Client\Provider; |
4
|
|
|
|
5
|
|
|
use Flipbox\OAuth2\Client\Provider\Exception\HubSpotIdentityProviderException; |
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
|
|
|
class HubSpot extends AbstractProvider |
12
|
|
|
{ |
13
|
|
|
use BearerAuthorizationTrait; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Domain |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
public $domain = 'https://app.hubspot.com'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Api domain |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
public $apiDomain = 'https://api.hubapi.com'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
protected $defaultScopes = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @inheritdoc |
36
|
|
|
*/ |
37
|
9 |
|
public function getBaseAuthorizationUrl() |
38
|
|
|
{ |
39
|
9 |
|
return $this->domain . '/oauth/authorize'; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @inheritdoc |
44
|
|
|
*/ |
45
|
15 |
|
public function getBaseAccessTokenUrl(array $params) |
46
|
|
|
{ |
47
|
15 |
|
return $this->apiDomain . '/oauth/v1/token'; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritdoc |
52
|
|
|
*/ |
53
|
3 |
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
54
|
|
|
{ |
55
|
3 |
|
return $this->apiDomain . '/oauth/v1/access-tokens/' . $token->getToken(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @inheritdoc |
60
|
|
|
*/ |
61
|
6 |
|
protected function getDefaultScopes() |
62
|
|
|
{ |
63
|
6 |
|
return $this->defaultScopes; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @inheritdoc |
68
|
|
|
*/ |
69
|
9 |
|
protected function getScopeSeparator() |
70
|
|
|
{ |
71
|
9 |
|
return ' '; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @inheritdoc |
76
|
|
|
*/ |
77
|
3 |
|
protected function getAuthorizationHeaders($token = null) |
78
|
|
|
{ |
79
|
3 |
|
if ($token === null) { |
80
|
|
|
return []; |
81
|
|
|
} |
82
|
|
|
return [ |
83
|
3 |
|
'Authorization' => sprintf("Bearer %s", $token) |
84
|
1 |
|
]; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @inheritdoc |
89
|
|
|
*/ |
90
|
12 |
|
protected function checkResponse(ResponseInterface $response, $data) |
91
|
|
|
{ |
92
|
12 |
|
if ($response->getStatusCode() >= 400) { |
93
|
3 |
|
throw HubSpotIdentityProviderException::clientException($response, $data); |
|
|
|
|
94
|
9 |
|
} elseif (isset($data['error'])) { |
95
|
3 |
|
throw HubSpotIdentityProviderException::oauthException($response, $data); |
|
|
|
|
96
|
|
|
} |
97
|
6 |
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @inheritdoc |
101
|
|
|
*/ |
102
|
3 |
|
protected function createResourceOwner(array $response, AccessToken $token) |
103
|
|
|
{ |
104
|
3 |
|
return new HubSpotResourceOwner($response); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
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.