Files
id/src/Id/HasAnikeenTokens.php
Maurice Preuß (envoyr) 7f908f4e6a refactored code
Signed-off-by: Maurice Preuß (envoyr) <hello@envoyr.com>
2025-04-28 04:47:50 +02:00

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;
}
}