1
|
|
|
<?php |
2
|
|
|
namespace Strava\API; |
3
|
|
|
|
4
|
|
|
use League\OAuth2\Client\Entity\User; |
5
|
|
|
use League\OAuth2\Client\Token\AccessToken as AccessToken; |
6
|
|
|
use League\OAuth2\Client\Tool\BearerAuthorizationTrait as BearerAuthorizationTrait; |
7
|
|
|
use League\OAuth2\Client\Provider\AbstractProvider as AbstractProvider; |
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Strava OAuth |
12
|
|
|
* The Strava implementation of the OAuth client |
13
|
|
|
* |
14
|
|
|
* @see: https://github.com/thephpleague/oauth2-client |
15
|
|
|
* @author Bas van Dorst |
16
|
|
|
*/ |
17
|
|
|
class OAuth extends AbstractProvider { |
18
|
|
|
use BearerAuthorizationTrait; |
19
|
|
|
|
20
|
|
|
public $scopes = ['write']; |
21
|
|
|
public $responseType = 'json'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @see AbstractProvider::urlAuthorize |
25
|
|
|
*/ |
26
|
1 |
|
public function urlAuthorize() |
27
|
|
|
{ |
28
|
1 |
|
return 'https://www.strava.com/oauth/authorize'; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @see AbstractProvider::urlAccessToken |
33
|
|
|
*/ |
34
|
1 |
|
public function urlAccessToken() |
35
|
|
|
{ |
36
|
1 |
|
return 'https://www.strava.com/oauth/token'; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @see AbstractProvider::urlUserDetails |
41
|
|
|
*/ |
42
|
1 |
|
public function urlUserDetails(AccessToken $token) |
|
|
|
|
43
|
|
|
{ |
44
|
1 |
|
return 'https://www.strava.com/api/v3/athlete'; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @see AbstractProvider::userDetails |
49
|
|
|
*/ |
50
|
1 |
|
public function userDetails($response, AccessToken $token) |
|
|
|
|
51
|
|
|
{ |
52
|
1 |
|
$user = new \stdClass; |
53
|
|
|
|
54
|
1 |
|
$user->uid = $response->id; |
55
|
1 |
|
$user->name = implode(' ', [$response->firstname, $response->lastname]); |
56
|
1 |
|
$user->firstName = $response->firstname; |
57
|
1 |
|
$user->lastName = $response->lastname; |
58
|
1 |
|
$user->email = $response->email; |
59
|
1 |
|
$user->location = $response->country; |
60
|
1 |
|
$user->imageUrl = $response->profile; |
61
|
1 |
|
$user->gender = $response->sex; |
62
|
|
|
|
63
|
1 |
|
return $user; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @see AbstractProvider::userUid |
68
|
|
|
*/ |
69
|
1 |
|
public function userUid($response, AccessToken $token) |
|
|
|
|
70
|
|
|
{ |
71
|
1 |
|
return $response->id; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @see AbstractProvider::userEmail |
76
|
|
|
*/ |
77
|
1 |
|
public function userEmail($response, AccessToken $token) |
|
|
|
|
78
|
|
|
{ |
79
|
1 |
|
return isset($response->email) && $response->email ? $response->email : null; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @see AbstractProvider::userScreenName |
84
|
|
|
*/ |
85
|
1 |
|
public function userScreenName($response, AccessToken $token) |
|
|
|
|
86
|
|
|
{ |
87
|
1 |
|
return implode(' ', [$response->firstname, $response->lastname]); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @see AbstractProvider::getBaseAuthorizationUrl |
92
|
|
|
*/ |
93
|
|
|
public function getBaseAuthorizationUrl() |
94
|
|
|
{ |
95
|
|
|
return 'https://www.strava.com/oauth/authorize'; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @see AbstractProvider::getBaseAccessTokenUrl |
100
|
|
|
*/ |
101
|
|
|
public function getBaseAccessTokenUrl(array $params) |
102
|
|
|
{ |
103
|
|
|
return 'https://www.strava.com/oauth/token'; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @see AbstractProvider::getResourceOwnerDetailsUrl |
108
|
|
|
*/ |
109
|
|
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
110
|
|
|
{ |
111
|
|
|
return ''; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @see AbstractProvider::getDefaultScopes |
116
|
|
|
*/ |
117
|
|
|
protected function getDefaultScopes() |
118
|
|
|
{ |
119
|
|
|
return ['write']; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @see AbstractProvider::checkResponse |
124
|
|
|
*/ |
125
|
|
|
protected function checkResponse(ResponseInterface $response, $data) |
126
|
|
|
{ |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @see AbstractProvider::createResourceOwner |
131
|
|
|
*/ |
132
|
|
|
protected function createResourceOwner(array $response, AccessToken $token) |
133
|
|
|
{ |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.