<?php
|
namespace JVBase\integrations;
|
|
if (!defined('ABSPATH')) {
|
exit;
|
}
|
|
class OAuthCredentials
|
{
|
public string $access_token;
|
public int $expires_at;
|
public ?string $refresh_token;
|
public ?string $revoke;
|
public array $scopes;
|
|
public function __construct(array $data)
|
{
|
$this->access_token = $data['access_token'] ?? '';
|
$this->expires_at = (int)($data['expires_at'] ?? 0);
|
$this->refresh_token = $data['refresh_token'] ?? null;
|
$this->scopes = $data['scopes'] ?? [];
|
}
|
|
public function isValid(): bool
|
{
|
return !empty($this->access_token) && $this->expires_at > 0;
|
}
|
|
public function isExpired(int $buffer = 60): bool
|
{
|
return $this->expires_at <= (time() + $buffer);
|
}
|
|
public function hasScopes(array $required): bool
|
{
|
return empty(array_diff($required, $this->scopes));
|
}
|
|
public function toArray(): array
|
{
|
return [
|
'access_token' => $this->access_token,
|
'expires_at' => $this->expires_at,
|
'refresh_token' => $this->refresh_token,
|
// 'scopes' => $this->scopes,
|
];
|
}
|
}
|