|
1
|
|
|
<?php namespace Stevenmaguire\OAuth2\Client\Provider; |
|
2
|
|
|
|
|
3
|
|
|
use League\OAuth2\Client\Provider\AbstractProvider; |
|
4
|
|
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; |
|
5
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
|
6
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
7
|
|
|
|
|
8
|
|
|
class Foursquare extends AbstractProvider |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Get authorization url to begin OAuth flow |
|
12
|
|
|
* |
|
13
|
|
|
* @return string |
|
14
|
|
|
*/ |
|
15
|
6 |
|
public function getBaseAuthorizationUrl() |
|
16
|
|
|
{ |
|
17
|
6 |
|
return 'https://foursquare.com/oauth2/authenticate'; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Get access token url to retrieve token |
|
22
|
|
|
* |
|
23
|
|
|
* @return string |
|
24
|
|
|
*/ |
|
25
|
8 |
|
public function getBaseAccessTokenUrl(array $params) |
|
26
|
|
|
{ |
|
27
|
8 |
|
return 'https://foursquare.com/oauth2/access_token'; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Get provider url to fetch user details |
|
32
|
|
|
* |
|
33
|
|
|
* @param AccessToken $token |
|
34
|
|
|
* |
|
35
|
|
|
* @return string |
|
36
|
|
|
*/ |
|
37
|
2 |
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
|
38
|
|
|
{ |
|
39
|
2 |
|
return 'https://api.foursquare.com/v2/users/self?v=20140806&oauth_token='.$token; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Get the default scopes used by this provider. |
|
44
|
|
|
* |
|
45
|
|
|
* This should not be a complete list of all scopes, but the minimum |
|
46
|
|
|
* required for the provider user interface! |
|
47
|
|
|
* |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
4 |
|
protected function getDefaultScopes() |
|
51
|
|
|
{ |
|
52
|
4 |
|
return []; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Check a provider response for errors. |
|
57
|
|
|
* |
|
58
|
|
|
* @throws IdentityProviderException |
|
59
|
|
|
* @param ResponseInterface $response |
|
60
|
|
|
* @param string $data Parsed response data |
|
61
|
|
|
* @return void |
|
62
|
|
|
*/ |
|
63
|
6 |
|
protected function checkResponse(ResponseInterface $response, $data) |
|
64
|
|
|
{ |
|
65
|
6 |
|
$statusCode = $response->getStatusCode(); |
|
66
|
6 |
|
if ($statusCode >= 400) { |
|
67
|
2 |
|
throw new IdentityProviderException( |
|
68
|
2 |
|
isset($data['meta']['errorDetail']) ? $data['meta']['errorDetail'] : $response->getReasonPhrase(), |
|
69
|
1 |
|
$statusCode, |
|
70
|
|
|
$response |
|
|
|
|
|
|
71
|
1 |
|
); |
|
72
|
|
|
} |
|
73
|
4 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Generate a user object from a successful user details request. |
|
77
|
|
|
* |
|
78
|
|
|
* @param object $response |
|
79
|
|
|
* @param AccessToken $token |
|
80
|
|
|
* @return FoursquareResourceOwner |
|
81
|
|
|
*/ |
|
82
|
2 |
|
protected function createResourceOwner(array $response, AccessToken $token) |
|
83
|
|
|
{ |
|
84
|
2 |
|
return new FoursquareResourceOwner($response); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
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: