modernize oauth token handling
This commit is contained in:
11 files changed
+600
-191
No files matched your search
@@ -7,61 +7,26 @@ class OAuthToken extends Model
|
||||
{
|
||||
protected static string $table = 'oauth_tokens';
|
||||
|
||||
protected static array $fields = ['scope', 'nonce', 'user_id', 'code', 'access_token', 'created', 'expires'];
|
||||
protected static array $fields = ['session_id', 'created', 'expires'];
|
||||
|
||||
protected static array $relations = ['user' => User::class];
|
||||
protected static array $relations = ['session' => OAuthSession::class];
|
||||
|
||||
private static array $possibleScopeValues = ['openid', 'email', 'profile'];
|
||||
private ?OAuthSession $session = null;
|
||||
|
||||
private array $scope = [];
|
||||
|
||||
private string $nonce = '';
|
||||
|
||||
private ?User $user = null;
|
||||
|
||||
private ?int $userId = null;
|
||||
|
||||
private string $code = '';
|
||||
|
||||
private string $accessToken = '';
|
||||
private ?int $sessionId = null;
|
||||
|
||||
private DateTime $created;
|
||||
|
||||
private DateTime $expires;
|
||||
|
||||
public function setScopeArray(array $scope): void
|
||||
public function setSession(OAuthSession $session): void
|
||||
{
|
||||
$this->scope = array_intersect($scope, self::$possibleScopeValues);
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
public function setScope(string $scope): void
|
||||
public function setSessionId(int $sessionId): void
|
||||
{
|
||||
$this->setScopeArray(explode(' ', $scope));
|
||||
}
|
||||
|
||||
public function setNonce(string $nonce): void
|
||||
{
|
||||
$this->nonce = $nonce;
|
||||
}
|
||||
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function setUserId(int $userId): void
|
||||
{
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
public function setCode(string $code): void
|
||||
{
|
||||
$this->code = $code;
|
||||
}
|
||||
|
||||
public function setAccessToken(string $accessToken): void
|
||||
{
|
||||
$this->accessToken = $accessToken;
|
||||
$this->sessionId = $sessionId;
|
||||
}
|
||||
|
||||
public function setCreatedDate(DateTime $created): void
|
||||
@@ -84,39 +49,14 @@ class OAuthToken extends Model
|
||||
$this->expires = new DateTime($expires);
|
||||
}
|
||||
|
||||
public function getScope(): string
|
||||
public function getSession(): ?OAuthSession
|
||||
{
|
||||
return implode(' ', $this->scope);
|
||||
return $this->session;
|
||||
}
|
||||
|
||||
public function getScopeArray(): array
|
||||
public function getSessionId(): ?int
|
||||
{
|
||||
return $this->scope;
|
||||
}
|
||||
|
||||
public function getNonce(): string
|
||||
{
|
||||
return $this->nonce;
|
||||
}
|
||||
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function getUserId(): ?int
|
||||
{
|
||||
return $this->userId;
|
||||
}
|
||||
|
||||
public function getCode(): string
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function getAccessToken(): string
|
||||
{
|
||||
return $this->accessToken;
|
||||
return $this->sessionId;
|
||||
}
|
||||
|
||||
public function getCreatedDate(): DateTime
|
||||
|
||||
Reference in new issue
Block a user