Add jwt handling, inspired by passport

This commit is contained in:
René Preuß
2021-03-30 23:19:36 +02:00
parent 32990da8a0
commit 14bf9d5480
14 changed files with 872 additions and 56 deletions

View File

@@ -0,0 +1,50 @@
<?php
namespace GhostZero\BitinflowAccounts\Traits;
use Illuminate\Container\Container;
use stdClass;
trait HasBitinflowTokens
{
/**
* The current access token for the authentication user.
*
* @var stdClass
*/
protected $accessToken;
/**
* Get the current access token being used by the user.
*
* @return stdClass|null
*/
public function bitinflowToken(): ?stdClass
{
return $this->accessToken;
}
/**
* Determine if the current API token has a given scope.
*
* @param string $scopeUserProvider
* @return bool
*/
public function bitinflowTokenCan(string $scope): bool
{
return $this->accessToken ? in_array($scope, $this->accessToken->scopes) : false;
}
/**
* Set the current access token for the user.
*
* @param stdClass $accessToken
* @return $this
*/
public function withBitinflowAccessToken(stdClass $accessToken): self
{
$this->accessToken = $accessToken;
return $this;
}
}