mirror of
https://github.com/anikeen-com/id.git
synced 2026-03-13 21:56:14 +00:00
43 lines
923 B
PHP
43 lines
923 B
PHP
<?php
|
|
|
|
namespace Anikeen\Id;
|
|
|
|
use stdClass;
|
|
|
|
trait HasAnikeenTokens
|
|
{
|
|
/**
|
|
* The current access token for the authentication user.
|
|
*/
|
|
protected ?stdClass $accessToken = null;
|
|
|
|
/**
|
|
* Get the current access token being used by the user.
|
|
*
|
|
* @return stdClass|null
|
|
*/
|
|
public function anikeenToken(): ?stdClass
|
|
{
|
|
return $this->accessToken;
|
|
}
|
|
|
|
/**
|
|
* Determine if the current API token has a given scope.
|
|
*/
|
|
public function anikeenTokenCan(string $scope): bool
|
|
{
|
|
$scopes = $this->accessToken ? $this->accessToken->scopes : [];
|
|
|
|
return in_array('*', $scopes) || in_array($scope, $this->accessToken->scopes);
|
|
}
|
|
|
|
/**
|
|
* Set the current access token for the user.
|
|
*/
|
|
public function withAnikeenAccessToken(stdClass $accessToken): self
|
|
{
|
|
$this->accessToken = $accessToken;
|
|
|
|
return $this;
|
|
}
|
|
} |