1
|
|
|
<?php |
2
|
|
|
namespace CrewLabs\OAuth2\Client\Provider; |
3
|
|
|
|
4
|
|
|
use League\OAuth2\Client\Provider\AbstractProvider; |
5
|
|
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; |
6
|
|
|
use League\OAuth2\Client\Provider\ResourceOwnerInterface; |
7
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
8
|
|
|
use League\OAuth2\Client\Tool\BearerAuthorizationTrait; |
9
|
|
|
use Psr\Http\Message\ResponseInterface; |
10
|
|
|
|
11
|
|
|
class Dribbble extends AbstractProvider |
12
|
|
|
{ |
13
|
|
|
use BearerAuthorizationTrait; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Get authorization url to begin OAuth flow |
17
|
|
|
* |
18
|
|
|
* @return string |
19
|
|
|
*/ |
20
|
6 |
|
public function getBaseAuthorizationUrl() |
21
|
|
|
{ |
22
|
6 |
|
return 'https://dribbble.com/oauth/authorize'; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Get access token url to retrieve token |
27
|
|
|
* |
28
|
|
|
* @param array $params |
29
|
|
|
* |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
12 |
|
public function getBaseAccessTokenUrl(array $params) |
33
|
|
|
{ |
34
|
12 |
|
return 'https://dribbble.com/oauth/token'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Get provider url to fetch user details |
39
|
|
|
* |
40
|
|
|
* @param AccessToken $token |
41
|
|
|
* |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
3 |
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
45
|
|
|
{ |
46
|
3 |
|
return 'https://api.dribbble.com/v1/user?' . http_build_query(['access_token' => $token->getToken()]); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Get the default scopes used by this provider. |
51
|
|
|
* |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
6 |
|
protected function getDefaultScopes() |
55
|
|
|
{ |
56
|
6 |
|
return ['public']; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Check a provider response for errors. |
61
|
|
|
* |
62
|
|
|
* @param ResponseInterface $response |
63
|
|
|
* @param array|string $data |
64
|
|
|
* |
65
|
|
|
* @throws IdentityProviderException |
66
|
|
|
*/ |
67
|
9 |
|
protected function checkResponse(ResponseInterface $response, $data) |
68
|
|
|
{ |
69
|
9 |
|
if ($response->getStatusCode() >= 400) { |
70
|
3 |
|
$errorString = (isset($data['error'])) ? $data['error'] : $response->getReasonPhrase(); |
71
|
3 |
|
throw new IdentityProviderException( |
72
|
2 |
|
$errorString, |
73
|
3 |
|
$response->getStatusCode(), |
74
|
|
|
$response |
|
|
|
|
75
|
2 |
|
); |
76
|
|
|
} |
77
|
6 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Generate a user object from a successful user details request. |
81
|
|
|
* |
82
|
|
|
* @param array $response |
83
|
|
|
* @param AccessToken $token |
84
|
|
|
* |
85
|
|
|
* @return League\OAuth2\Client\Provider\ResourceOwnerInterface |
86
|
|
|
*/ |
87
|
3 |
|
protected function createResourceOwner(array $response, AccessToken $token) |
88
|
|
|
{ |
89
|
3 |
|
return new DribbbleResourceOwner($response); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
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: