Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 9 |
External | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 9 |
getUser | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 8 |
|||
getTtl | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\AuthConnector\Connector; |
4 | |
5 | use Illuminate\Http\Response; |
6 | use Illuminate\Support\Facades\Log; |
7 | use \Qmp\Laravel\MicroService\Client\Tools\Request as ClientRequest; |
8 | use \Qmp\Laravel\MicroService\Client\Client; |
9 | use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; |
10 | |
11 | class External implements ConnectorInterface |
12 | { |
13 | private $ttl = 0; |
14 | |
15 | /** |
16 | * @param string $token |
17 | * @return false|array |
18 | */ |
19 | public function getUser(string $token) |
20 | { |
21 | $request = ClientRequest::createObject('service_external_users', 'users/token', ['headers' => ['Authorization' => 'Bearer ' . $token]]); |
22 | $response = Client::systemSend('get', $request); |
23 | |
24 | if ( |
25 | $response->code !== Response::HTTP_OK |
26 | || empty($response->content['user_id']) |
27 | || empty($response->content['access_token']['ttl']) |
28 | ) { |
29 | throw new \Exception('Error on external auth : ' . $response->code . ':' . $response->body); |
30 | } |
31 | |
32 | $this->ttl = $response->content['access_token']['ttl']; |
33 | |
34 | return [ |
35 | 'id' => $response->content['user_id'] |
36 | ]; |
37 | } |
38 | |
39 | public function getTtl() |
40 | { |
41 | return $this->ttl; |
42 | } |
43 | } |