|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: arthur |
|
5
|
|
|
* Date: 13.10.18 |
|
6
|
|
|
* Time: 20:50 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Modules\Auth0\Services; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use Auth0\Login\Repository\Auth0UserRepository; |
|
|
|
|
|
|
13
|
|
|
use Modules\Auth0\Drivers\Auth0UserProfileStorageDriver; |
|
14
|
|
|
use Modules\User\Contracts\UserServiceContract; |
|
15
|
|
|
use MongoDB\BSON\ObjectId; |
|
16
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
|
17
|
|
|
|
|
18
|
|
|
class Auth0Service extends Auth0UserRepository |
|
19
|
|
|
{ |
|
20
|
|
|
protected $service; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Auth0UserRepository constructor. |
|
24
|
|
|
* |
|
25
|
|
|
* @param $service |
|
26
|
|
|
*/ |
|
27
|
5 |
|
public function __construct(UserServiceContract $service) |
|
28
|
|
|
{ |
|
29
|
5 |
|
$this->service = $service; |
|
30
|
5 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/* This class is used on api authN to fetch the user based on the jwt.*/ |
|
33
|
|
|
public function getUserByDecodedJWT($jwt) |
|
34
|
|
|
{ |
|
35
|
|
|
/* |
|
36
|
|
|
* The `sub` claim in the token represents the subject of the token |
|
37
|
|
|
* and it is always the `user_id` |
|
38
|
|
|
*/ |
|
39
|
|
|
$jwt->user_id = $jwt->sub; |
|
40
|
|
|
|
|
41
|
|
|
return $this->upsertUser($jwt); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getUserByUserInfo($userInfo) |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->upsertUser($userInfo['profile']); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
protected function upsertUser($profile) |
|
50
|
|
|
{ |
|
51
|
|
|
if (!isset($profile->user_id)) { |
|
52
|
|
|
throw new BadRequestHttpException('Missing token information: Auth0 user id is not set'); |
|
53
|
|
|
} |
|
54
|
|
|
$identifier = explode('|', $profile->user_id); |
|
55
|
|
|
$identityProvider = $identifier[0]; |
|
56
|
|
|
$id = $identifier[1]; |
|
57
|
|
|
|
|
58
|
|
|
$user = $this->service->find($id); |
|
59
|
|
|
|
|
60
|
|
|
if ($user === null) { |
|
61
|
|
|
$user = $this->service->newUser([ |
|
62
|
|
|
"identity_id" => $id |
|
63
|
|
|
]); |
|
64
|
|
|
} |
|
65
|
|
|
$driver = new Auth0UserProfileStorageDriver($user, $profile, $identityProvider); |
|
66
|
|
|
$user = $driver->run(); |
|
67
|
|
|
|
|
68
|
|
|
return $user; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
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