- Removed legacy Outlook integration, including views, controllers, and models. - Introduced Microsoft Entra ID OAuth flows with enhanced permission checks and token management. - Migrated database structure: replaced `outlook_tokens` table with `oauth_tokens` table for multi-provider support. - Added comprehensive tests for Entra ID federation, including connection flow, token refresh, and permission checks. - Standardized OAuth implementation using `EntraController` and consolidated token models into `OauthToken`.
64 lines
1.3 KiB
PHP
64 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\{Builder, Model};
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property int $user_id
|
|
* @property string $provider
|
|
* @property string $access_token
|
|
* @property string|null $refresh_token
|
|
* @property string $token_type
|
|
* @property string|null $scopes
|
|
* @property \Illuminate\Support\Carbon $expires_at
|
|
*/
|
|
class OauthToken extends Model
|
|
{
|
|
protected $table = 'oauth_tokens';
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'provider',
|
|
'access_token',
|
|
'refresh_token',
|
|
'token_type',
|
|
'scopes',
|
|
'expires_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'expires_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<User, $this>
|
|
*/
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function isExpired(): bool
|
|
{
|
|
return $this->expires_at->isPast();
|
|
}
|
|
|
|
/**
|
|
* @param Builder<OauthToken> $query
|
|
*
|
|
* @return Builder<OauthToken>
|
|
*/
|
|
public function scopeForProvider(Builder $query, string $provider): Builder
|
|
{
|
|
return $query->where('provider', $provider);
|
|
}
|
|
}
|