mirror of
https://github.com/bitinflow/accounts.git
synced 2026-03-15 14:35:52 +00:00
Add jwt handling, inspired by passport
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user