1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Controller\Oauth; |
4
|
|
|
|
5
|
|
|
use ControleOnline\Service\UserService; |
6
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
7
|
|
|
use Exception; |
8
|
|
|
use League\OAuth2\Client\Token\AccessToken; |
|
|
|
|
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
|
|
|
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
|
|
|
11
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
|
|
|
12
|
|
|
|
13
|
|
|
|
14
|
|
|
class DefaultClientController extends AbstractController |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
protected $clientId; |
18
|
|
|
protected $clientSecret; |
19
|
|
|
protected $provider; |
20
|
|
|
|
21
|
|
|
public function __construct(protected EntityManagerInterface $manager, protected UserService $userService) {} |
22
|
|
|
|
23
|
|
|
protected function connectAction() |
24
|
|
|
{ |
25
|
|
|
$authUrl = $this->provider->getAuthorizationUrl(); |
26
|
|
|
header('Location: ' . $authUrl); |
27
|
|
|
exit; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
|
32
|
|
|
protected function returnAction(Request $request): JsonResponse |
33
|
|
|
{ |
34
|
|
|
try { |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
if ($request->get('code')) |
38
|
|
|
$token = $this->provider->getAccessToken('authorization_code', [ |
39
|
|
|
'code' => $request->get('code') |
40
|
|
|
]); |
41
|
|
|
|
42
|
|
|
if ($request->get('access_token')) |
43
|
|
|
$token = new AccessToken([ |
44
|
|
|
'access_token' => $request->get('access_token'), |
45
|
|
|
]); |
46
|
|
|
|
47
|
|
|
if ($request->get('code')) |
48
|
|
|
$token = $this->provider->getAccessToken('authorization_code', [ |
49
|
|
|
'code' => $request->get('code') |
50
|
|
|
]); |
51
|
|
|
|
52
|
|
|
$ownerDetails = $this->provider->getResourceOwner($token); |
|
|
|
|
53
|
|
|
|
54
|
|
|
$user = $this->userService->discoveryUser($ownerDetails->getEmail(), md5(microtime()), $ownerDetails->getFirstName(), $ownerDetails->getLasttName()); |
55
|
|
|
|
56
|
|
|
$data = [ |
57
|
|
|
'id' => $user->getPeople()->getId(), |
58
|
|
|
'username' => $user->getUsername(), |
59
|
|
|
'roles' => $user->getRoles(), |
60
|
|
|
'api_key' => $user->getApiKey(), |
61
|
|
|
'people' => $user->getPeople()->getId(), |
62
|
|
|
'mycompany' => $this->userService->getCompanyId($user), |
63
|
|
|
'realname' => $ownerDetails->getFirstName(), |
64
|
|
|
'avatar' => $user->getPeople()->getImage() ? '/files/' . $user->getPeople()->getImage()->getId() . '/download' : null, |
65
|
|
|
'email' => $ownerDetails->getEmail(), |
66
|
|
|
'active' => (int) $user->getPeople()->getEnabled(), |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
|
71
|
|
|
return new JsonResponse([ |
72
|
|
|
'response' => [ |
73
|
|
|
'data' => $data, |
74
|
|
|
'count' => 1, |
75
|
|
|
'error' => '', |
76
|
|
|
'success' => true, |
77
|
|
|
], |
78
|
|
|
]); |
79
|
|
|
} catch (Exception $e) { |
80
|
|
|
|
81
|
|
|
return new JsonResponse([ |
82
|
|
|
'response' => [ |
83
|
|
|
'data' => [], |
84
|
|
|
'count' => 0, |
85
|
|
|
'error' => $e->getMessage(), |
86
|
|
|
'success' => false, |
87
|
|
|
], |
88
|
|
|
]); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths