1
|
|
|
<?php namespace Bogstag\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 League\OAuth2\Client\Tool\BearerAuthorizationTrait; |
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
8
|
|
|
|
9
|
|
|
class Trakt extends AbstractProvider |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
use BearerAuthorizationTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $baseUrlApi = 'https://api.trakt.tv'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $basUrl = 'https://trakt.tv'; |
23
|
|
|
|
24
|
|
|
protected $traktApiVersion = 2; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Get authorization url to begin OAuth flow |
28
|
|
|
* As noted in api docs you should use the normal url not the api url. |
29
|
|
|
* |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
|
|
public function getBaseAuthorizationUrl() |
33
|
|
|
{ |
34
|
|
|
return $this->basUrl . '/oauth/authorize'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @inheritDoc |
39
|
|
|
*/ |
40
|
|
|
public function getBaseAccessTokenUrl(array $params) |
41
|
|
|
{ |
42
|
|
|
return $this->baseUrlApi . '/oauth/token'; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @inheritDoc |
47
|
|
|
*/ |
48
|
|
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
49
|
|
|
{ |
50
|
|
|
return $this->baseUrlApi . '/users/settings'; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritDoc} |
55
|
|
|
*/ |
56
|
|
|
public function getHeaders($token = null) |
57
|
|
|
{ |
58
|
|
|
$headers = [ |
59
|
|
|
'Content-Type' => 'application/json', |
60
|
|
|
'trakt-api-version' => $this->traktApiVersion, |
61
|
|
|
'trakt-api-key' => $this->clientId |
62
|
|
|
]; |
63
|
|
|
|
64
|
|
|
return array_merge(parent::getHeaders($token), $headers); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @inheritDoc |
69
|
|
|
*/ |
70
|
|
|
protected function getDefaultScopes() |
71
|
|
|
{ |
72
|
|
|
return []; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @inheritDoc |
77
|
|
|
*/ |
78
|
|
|
protected function checkResponse(ResponseInterface $response, $data) |
79
|
|
|
{ |
80
|
|
|
if (isset($data['error'])) { |
81
|
|
|
throw new IdentityProviderException((isset($data['error']['message']) ? $data['error']['message'] : $response->getReasonPhrase()), |
82
|
|
|
$response->getStatusCode(), $response); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @inheritDoc |
88
|
|
|
*/ |
89
|
|
|
protected function createResourceOwner(array $response, AccessToken $token) |
90
|
|
|
{ |
91
|
|
|
return new TraktResourceOwner($response); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
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: