|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Larabros\OAuth2\Client\Provider; |
|
4
|
|
|
|
|
5
|
|
|
use League\OAuth2\Client\Provider\AbstractProvider; |
|
6
|
|
|
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; |
|
7
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
|
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* An OAuth2 provider class for PSN. |
|
12
|
|
|
* |
|
13
|
|
|
* @package OAuth2 |
|
14
|
|
|
* @author Hassan Khan <[email protected]> |
|
15
|
|
|
* @link https://github.com/larabros/oauth2-psn |
|
16
|
|
|
* @license MIT |
|
17
|
|
|
*/ |
|
18
|
|
|
class Psn extends AbstractProvider |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var string Key used in the access token response to identify the resource owner. |
|
22
|
|
|
*/ |
|
23
|
|
|
const ACCESS_TOKEN_RESOURCE_OWNER_ID = 'accountId'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritDoc} |
|
27
|
|
|
*/ |
|
28
|
6 |
|
public function getBaseAuthorizationUrl() |
|
29
|
|
|
{ |
|
30
|
6 |
|
return 'https://auth.api.sonyentertainmentnetwork.com/2.0/oauth/authorize'; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritDoc} |
|
35
|
|
|
*/ |
|
36
|
12 |
|
public function getBaseAccessTokenUrl(array $params) |
|
37
|
|
|
{ |
|
38
|
12 |
|
return 'https://auth.api.sonyentertainmentnetwork.com/2.0/oauth/token'; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritDoc} |
|
43
|
|
|
*/ |
|
44
|
2 |
|
public function getResourceOwnerDetailsUrl(AccessToken $token) |
|
45
|
|
|
{ |
|
46
|
2 |
|
return 'https://vl.api.np.km.playstation.net/vl/api/v1/mobile/users/me/info'; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritDoc} |
|
51
|
|
|
*/ |
|
52
|
4 |
|
protected function getDefaultScopes() |
|
53
|
|
|
{ |
|
54
|
4 |
|
return ['psn:s2s']; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritDoc} |
|
59
|
|
|
*/ |
|
60
|
10 |
|
protected function checkResponse(ResponseInterface $response, $data) |
|
61
|
|
|
{ |
|
62
|
10 |
|
if (isset($data['error'])) { |
|
63
|
4 |
|
if (is_array($data['error'])) { |
|
64
|
2 |
|
throw new IdentityProviderException( |
|
65
|
2 |
|
$data['error']['messageKey'].': '.$data['error']['message'] ?: $response->getReasonPhrase(), |
|
66
|
2 |
|
$data['error']['code'] ?: $response->getStatusCode(), |
|
67
|
|
|
$response |
|
|
|
|
|
|
68
|
2 |
|
); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
2 |
|
throw new IdentityProviderException( |
|
72
|
2 |
|
$data['error_description'] ?: $response->getReasonPhrase(), |
|
73
|
2 |
|
$data['error_code'] ?: $response->getStatusCode(), |
|
74
|
|
|
$response |
|
|
|
|
|
|
75
|
2 |
|
); |
|
76
|
|
|
} |
|
77
|
6 |
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* {@inheritDoc} |
|
81
|
|
|
*/ |
|
82
|
2 |
|
protected function createResourceOwner(array $response, AccessToken $token) |
|
83
|
|
|
{ |
|
84
|
2 |
|
return new PsnResourceOwner($response); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* {@inheritDoc} |
|
89
|
|
|
*/ |
|
90
|
4 |
|
protected function getAuthorizationHeaders($token = null) |
|
91
|
|
|
{ |
|
92
|
|
|
return [ |
|
93
|
4 |
|
'Bearer' => $token, |
|
94
|
4 |
|
'X-NP-ACCESS-TOKEN' => $token, |
|
95
|
4 |
|
]; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
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: