|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tgallice\OAuth2\Client\Provider; |
|
4
|
|
|
|
|
5
|
|
|
use League\OAuth2\Client\Provider\AbstractProvider; |
|
6
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
|
7
|
|
|
use League\OAuth2\Client\Tool\BearerAuthorizationTrait; |
|
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
9
|
|
|
use Tgallice\OAuth2\Client\Provider\Exception\BufferProviderException; |
|
10
|
|
|
|
|
11
|
|
|
class Buffer extends AbstractProvider |
|
12
|
|
|
{ |
|
13
|
|
|
use BearerAuthorizationTrait; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Buffer app base url |
|
17
|
|
|
* |
|
18
|
|
|
* @const string |
|
19
|
|
|
*/ |
|
20
|
|
|
const BASE_BUFFER_URL = 'https://bufferapp.com'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Buffer API base url |
|
24
|
|
|
* |
|
25
|
|
|
* @const string |
|
26
|
|
|
*/ |
|
27
|
|
|
const BASE_BUFFER_API_URL = 'https://api.bufferapp.com'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Buffer API version |
|
31
|
|
|
* |
|
32
|
|
|
* @const string |
|
33
|
|
|
*/ |
|
34
|
|
|
const BUFFER_API_VERSION = 1; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @inheritdoc |
|
38
|
|
|
*/ |
|
39
|
2 |
|
public function getBaseAuthorizationUrl() |
|
40
|
|
|
{ |
|
41
|
2 |
|
return static::BASE_BUFFER_URL . '/oauth2/authorize'; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @inheritdoc |
|
46
|
|
|
*/ |
|
47
|
6 |
|
public function getBaseAccessTokenUrl(array $params) |
|
48
|
|
|
{ |
|
49
|
6 |
|
return $this->getApiUrl() . '/oauth2/token.json'; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @inheritdoc |
|
54
|
|
|
*/ |
|
55
|
2 |
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
|
56
|
|
|
{ |
|
57
|
2 |
|
return $this->getApiUrl() . '/user.json'; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get the Buffer API URL |
|
62
|
|
|
* |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
10 |
|
public function getApiUrl() |
|
66
|
|
|
{ |
|
67
|
10 |
|
return static::BASE_BUFFER_API_URL . '/' . static::BUFFER_API_VERSION; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @inheritdoc |
|
72
|
|
|
*/ |
|
73
|
2 |
|
protected function getDefaultScopes() |
|
74
|
|
|
{ |
|
75
|
2 |
|
return []; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @inheritdoc |
|
80
|
|
|
*/ |
|
81
|
4 |
|
protected function checkResponse(ResponseInterface $response, $data) |
|
82
|
|
|
{ |
|
83
|
4 |
|
if ($response->getStatusCode() >= 400) { |
|
84
|
2 |
|
throw new BufferProviderException( |
|
85
|
2 |
|
$data['error'], |
|
86
|
2 |
|
isset($data['code']) ? (int) $data['code'] : $response->getStatusCode(), |
|
87
|
|
|
$response |
|
|
|
|
|
|
88
|
2 |
|
); |
|
89
|
|
|
} |
|
90
|
2 |
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @inheritdoc |
|
94
|
|
|
*/ |
|
95
|
2 |
|
protected function createResourceOwner(array $response, AccessToken $token) |
|
96
|
|
|
{ |
|
97
|
2 |
|
return new BufferUser($response); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: