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