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
|
|
|
protected function returnAction(Request $request): JsonResponse |
31
|
|
|
{ |
32
|
|
|
try { |
33
|
|
|
|
34
|
|
|
if ($request->get('code')) |
35
|
|
|
$token = $this->provider->getAccessToken('authorization_code', [ |
36
|
|
|
'code' => $request->get('code') |
37
|
|
|
]); |
38
|
|
|
|
39
|
|
|
if ($request->get('access_token')) |
40
|
|
|
$token = new AccessToken([ |
41
|
|
|
'access_token' => $request->get('access_token'), |
42
|
|
|
]); |
43
|
|
|
|
44
|
|
|
if ($request->get('code')) |
45
|
|
|
$token = $this->provider->getAccessToken('authorization_code', [ |
46
|
|
|
'code' => $request->get('code') |
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
$ownerDetails = $this->provider->getResourceOwner($token); |
|
|
|
|
50
|
|
|
|
51
|
|
|
$user = $this->userService->discoveryUser( |
52
|
|
|
$ownerDetails->getEmail(), |
53
|
|
|
md5(microtime()), |
54
|
|
|
$ownerDetails->getFirstName(), |
55
|
|
|
'' |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
$data = $this->userService->getUserSession($user); |
59
|
|
|
|
60
|
|
|
return new JsonResponse([ |
61
|
|
|
'response' => [ |
62
|
|
|
'data' => $data, |
63
|
|
|
'count' => 1, |
64
|
|
|
'error' => '', |
65
|
|
|
'success' => true, |
66
|
|
|
], |
67
|
|
|
]); |
68
|
|
|
} catch (Exception $e) { |
69
|
|
|
|
70
|
|
|
return new JsonResponse([ |
71
|
|
|
'response' => [ |
72
|
|
|
'data' => [], |
73
|
|
|
'count' => 0, |
74
|
|
|
'error' => $e->getMessage(), |
75
|
|
|
'success' => false, |
76
|
|
|
], |
77
|
|
|
]); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
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