1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Rinvex\Oauth\Models; |
6
|
|
|
|
7
|
|
|
use Illuminate\Database\Eloquent\Model; |
8
|
|
|
use Rinvex\Support\Traits\ValidatingTrait; |
9
|
|
|
|
10
|
|
|
class RefreshToken extends Model |
11
|
|
|
{ |
12
|
|
|
use ValidatingTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* {@inheritdoc} |
16
|
|
|
*/ |
17
|
|
|
protected $fillable = [ |
18
|
|
|
'identifier', |
19
|
|
|
'access_token_identifier', |
20
|
|
|
'is_revoked', |
21
|
|
|
'expires_at', |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
protected $casts = [ |
28
|
|
|
'identifier' => 'string', |
29
|
|
|
'access_token_identifier' => 'string', |
30
|
|
|
'is_revoked' => 'boolean', |
31
|
|
|
'expires_at' => 'date', |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
protected $observables = [ |
38
|
|
|
'validating', |
39
|
|
|
'validated', |
40
|
|
|
]; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The default rules that the model will validate against. |
44
|
|
|
* |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
protected $rules = []; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Whether the model should throw a |
51
|
|
|
* ValidationException if it fails validation. |
52
|
|
|
* |
53
|
|
|
* @var bool |
54
|
|
|
*/ |
55
|
|
|
protected $throwValidationExceptions = true; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Create a new Eloquent model instance. |
59
|
|
|
* |
60
|
|
|
* @param array $attributes |
61
|
|
|
*/ |
62
|
|
|
public function __construct(array $attributes = []) |
63
|
|
|
{ |
64
|
|
|
$this->setTable(config('rinvex.oauth.tables.refresh_tokens')); |
65
|
|
|
$this->mergeRules([ |
66
|
|
|
'identifier' => 'required|string|strip_tags|max:100', |
67
|
|
|
'access_token_identifier' => 'required|string|max:100', |
68
|
|
|
'is_revoked' => 'sometimes|boolean', |
69
|
|
|
'expires_at' => 'nullable|date', |
70
|
|
|
]); |
71
|
|
|
|
72
|
|
|
parent::__construct($attributes); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get the access token that the refresh token belongs to. |
77
|
|
|
* |
78
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
79
|
|
|
*/ |
80
|
|
|
public function accessToken() |
81
|
|
|
{ |
82
|
|
|
return $this->belongsTo(config('rinvex.oauth.models.access_token')); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Revoke the token instance. |
87
|
|
|
* |
88
|
|
|
* @return bool |
89
|
|
|
*/ |
90
|
|
|
public function revoke() |
91
|
|
|
{ |
92
|
|
|
return $this->forceFill(['is_revoked' => true])->save(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Determine if the token is a transient JWT token. |
97
|
|
|
* |
98
|
|
|
* @return bool |
99
|
|
|
*/ |
100
|
|
|
public function transient() |
101
|
|
|
{ |
102
|
|
|
return false; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Determine if the token is revoked. |
107
|
|
|
* |
108
|
|
|
* @return bool |
109
|
|
|
*/ |
110
|
|
|
public function isRevoked() |
111
|
|
|
{ |
112
|
|
|
return $this->is_revoked; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|