mirror of
https://github.com/anikeen-com/id.git
synced 2026-03-14 22:26:14 +00:00
refactored code
Signed-off-by: Maurice Preuß (envoyr) <hello@envoyr.com>
This commit is contained in:
43
src/Id/HasAnikeenTokens.php
Normal file
43
src/Id/HasAnikeenTokens.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user