Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| RefreshToken | |
0.00% |
0 / 7 |
|
0.00% |
0 / 6 |
42 | |
0.00% |
0 / 1 |
| setCustomIdAttribute | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getCustomIdAttribute | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| accessToken | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| revoke | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| transient | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getConnectionName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Models\Passport; |
| 4 | |
| 5 | use App\Http\Models\Moloquent; |
| 6 | use App\Observers\RefreshTokenObserver; |
| 7 | use Illuminate\Database\Eloquent\Attributes\ObservedBy; |
| 8 | use Illuminate\Database\Eloquent\Relations\BelongsTo; |
| 9 | use Laravel\Passport\Passport; |
| 10 | |
| 11 | #[ObservedBy([RefreshTokenObserver::class])] |
| 12 | class RefreshToken extends Moloquent |
| 13 | { |
| 14 | /** |
| 15 | * The database table used by the model. |
| 16 | * |
| 17 | * @var string |
| 18 | */ |
| 19 | protected $table = 'oauth_refresh_tokens'; |
| 20 | protected $fillable = ['id', 'custom_id', 'access_token_id', 'revoked', 'expires_at']; |
| 21 | // protected $primaryKey = 'id'; |
| 22 | public $incrementing = false; |
| 23 | protected $keyType = 'string'; |
| 24 | |
| 25 | public function setCustomIdAttribute($value) |
| 26 | { |
| 27 | $this->attributes['id'] = $value; |
| 28 | $this->attributes['custom_id'] = $value; |
| 29 | } |
| 30 | |
| 31 | public function getCustomIdAttribute($value = null) |
| 32 | { |
| 33 | return $this->attributes['custom_id'] ?? null; |
| 34 | } |
| 35 | /** |
| 36 | * The attributes that should be cast to native types. |
| 37 | * |
| 38 | * @var array |
| 39 | */ |
| 40 | protected $casts = [ |
| 41 | 'expires_at' => 'datetime', |
| 42 | 'revoked' => 'bool', |
| 43 | ]; |
| 44 | |
| 45 | /** |
| 46 | * Indicates if the model should be timestamped. |
| 47 | * |
| 48 | * @var bool |
| 49 | */ |
| 50 | public $timestamps = false; |
| 51 | |
| 52 | /** |
| 53 | * Get the access token that the refresh token belongs to. |
| 54 | */ |
| 55 | public function accessToken(): BelongsTo |
| 56 | { |
| 57 | return $this->belongsTo(Passport::tokenModel()); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Revoke the token instance. |
| 62 | */ |
| 63 | public function revoke(): bool |
| 64 | { |
| 65 | return $this->forceFill(['revoked' => true])->save(); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Determine if the token is a transient JWT token. |
| 70 | */ |
| 71 | public function transient(): bool |
| 72 | { |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Get the current connection name for the model. |
| 78 | */ |
| 79 | public function getConnectionName(): ?string |
| 80 | { |
| 81 | return config('passport.storage.database.connection') ?? $this->connection; |
| 82 | } |
| 83 | |
| 84 | } |