1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Hello\Models\Users\Traits; |
4
|
|
|
|
5
|
|
|
use ByTIC\Auth\Models\Users\Traits\AbstractUserTrait; |
6
|
|
|
use ByTIC\Hello\Models\Clients\PersonalAccess\ClientsManager; |
7
|
|
|
use ByTIC\Hello\Models\Traits\HasApiTokensTrait; |
8
|
|
|
use ByTIC\Hello\Models\Users\Resolvers\UsersResolvers; |
9
|
|
|
use ByTIC\Hello\Utility\ModelsHelper; |
10
|
|
|
use League\OAuth2\Server\Entities\Traits\EntityTrait; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Trait UserTrait |
14
|
|
|
* @package ByTIC\Hello\Models\Users\ |
15
|
|
|
* |
16
|
|
|
* @property string $access_token |
17
|
|
|
* @property string $access_jwt |
18
|
|
|
*/ |
19
|
|
|
trait UserTrait |
20
|
|
|
{ |
21
|
|
|
use AbstractUserTrait { |
22
|
|
|
doAuthentication as doAuthenticationTrait; |
23
|
|
|
} |
24
|
|
|
use HasApiTokensTrait, EntityTrait; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
3 |
|
public function getIdentifier() |
30
|
|
|
{ |
31
|
3 |
|
if (empty($this->identifier)) { |
32
|
2 |
|
$this->initIdentifier(); |
33
|
|
|
} |
34
|
3 |
|
return $this->identifier; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function doAuthentication() |
38
|
|
|
{ |
39
|
|
|
$token = $this->token(); |
40
|
|
|
$this->access_token = $token->getIdentifier(); |
41
|
|
|
$this->access_jwt = $token->convertToJWT(app('hello.keys.private'))->__toString(); |
42
|
|
|
$this->doAuthenticationTrait(); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function checkAccessToken() |
46
|
|
|
{ |
47
|
|
|
if (empty($this->access_token)) { |
48
|
|
|
$token = $this->token(); |
49
|
|
|
$this->access_token = $token->getIdentifier(); |
50
|
|
|
$this->access_jwt = $token->convertToJWT(app('hello.keys.private'))->__toString(); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
2 |
|
protected function initIdentifier() |
55
|
|
|
{ |
56
|
2 |
|
$this->setIdentifier(UsersResolvers::identifier($this)); |
57
|
2 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return \ByTIC\Hello\Models\AccessTokens\Token|null |
61
|
|
|
*/ |
62
|
|
|
protected function generateToken() |
63
|
|
|
{ |
64
|
|
|
$userTokens = ModelsHelper::accessTokens()->getValidUserTokens($this, ClientsManager::get()); |
65
|
|
|
if (count($userTokens) < 1) { |
66
|
|
|
return $this->createToken($this->generateTokenName()); |
67
|
|
|
} |
68
|
|
|
return $userTokens->current(); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.