1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2016 Peter Deltchev |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Poniverse\Lib\Service\Poniverse; |
20
|
|
|
|
21
|
|
|
use Poniverse\Lib\Errors\InvalidAccessTokenException; |
22
|
|
|
use Poniverse\Lib\Service\Service; |
23
|
|
|
|
24
|
|
|
class AccessTokenInfo extends Service { |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param \Psr\Http\Message\ResponseInterface $response |
28
|
|
|
* @throws InvalidAccessTokenException |
29
|
|
|
* @throws \Poniverse\Lib\Errors\ApiException |
30
|
|
|
*/ |
31
|
|
|
protected function handleError(\Psr\Http\Message\ResponseInterface $response) { |
32
|
|
|
if (404 === $response->getStatusCode()) { |
33
|
|
|
throw new InvalidAccessTokenException('This access token is expired or invalid!'); |
34
|
|
|
} else { |
35
|
|
|
throw new \Poniverse\Lib\Errors\ApiException( |
36
|
|
|
$response->getStatusCode(), |
37
|
|
|
['response' => var_export($response, true)], |
|
|
|
|
38
|
|
|
'An unknown error occurred while contacting the Poniverse API.'); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Gets information about the given access token. |
44
|
|
|
* |
45
|
|
|
* @link https://tools.ietf.org/html/draft-richer-oauth-introspection-06 |
46
|
|
|
* |
47
|
|
|
* @param $accessTokenToIntrospect |
48
|
|
|
* @return \Poniverse\Lib\AccessToken |
49
|
|
|
*/ |
50
|
|
|
public function introspect($accessTokenToIntrospect) { |
51
|
|
|
$clientToken = $this->client->getOAuthProvider()->getAccessToken('client_credentials'); |
52
|
|
|
$this->client->setAccessToken($clientToken); |
53
|
|
|
|
54
|
|
|
$request = $this->request( |
55
|
|
|
'post', |
56
|
|
|
$this->client->getPoniverseUrl() . "/v1/meta/introspect?token={$accessTokenToIntrospect}", |
57
|
|
|
['headers' => array_merge( |
58
|
|
|
['Accept' => 'application/json'], |
59
|
|
|
$this->client->getAuthHeader() |
60
|
|
|
)] |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
$response = json_decode($request->getBody(), true); |
64
|
|
|
|
65
|
|
|
$tokenInfo = new \Poniverse\Lib\AccessToken($accessTokenToIntrospect); |
66
|
|
|
$tokenInfo |
67
|
|
|
->setIsActive($response['active']) |
68
|
|
|
->setScopes($response['scope']) |
69
|
|
|
->setClientId($response['client_id']); |
70
|
|
|
return $tokenInfo; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
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: