| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace App\Module\OAuth\Models;
- use App\Models\User;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- /**
- * App\Module\OAuth\Models\OAuthAccessToken
- *
- * field start
- * @property int $id
- * @property string $client_id 客户端ID
- * @property int $user_id 用户ID
- * @property string $access_token 访问令牌
- * @property string $refresh_token
- * @property string $expires_at 过期时间
- * @property object|array $scope 权限范围
- * @property int $revoked
- * @property \Carbon\Carbon $created_at
- * @property \Carbon\Carbon $updated_at
- * field end
- */
- class OAuthAccessToken extends Model
- {
- protected $table = 'oauth_access_tokens';
- // attrlist start
- protected $fillable = [
- 'id',
- 'client_id',
- 'user_id',
- 'access_token',
- 'refresh_token',
- 'expires_at',
- 'scope',
- 'revoked',
- ];
- // attrlist end
- protected $fillable = [
- 'client_id',
- 'user_id',
- 'access_token',
- 'refresh_token',
- 'expires_at',
- 'scope',
- 'revoked'
- ];
- protected $casts = [
- 'expires_at' => 'datetime',
- 'revoked' => 'boolean',
- 'scope' => 'json'
- ];
- /**
- * 获取关联的用户
- */
- public function user(): BelongsTo
- {
- return $this->belongsTo(User::class);
- }
- /**
- * 获取关联的客户端
- */
- public function client(): BelongsTo
- {
- return $this->belongsTo(OAuthClient::class, 'client_id');
- }
- /**
- * 检查令牌是否已过期
- */
- public function isExpired(): bool
- {
- return $this->expires_at->isPast();
- }
- /**
- * 检查令牌是否有效
- */
- public function isValid(): bool
- {
- return !$this->isExpired() && !$this->revoked;
- }
- }
|