mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-28 07:50:23 +05:30
Updated access token repository example
This commit is contained in:
parent
be9bd76f35
commit
5cba35456f
13
examples/src/Entities/AccessTokenEntity.php
Normal file
13
examples/src/Entities/AccessTokenEntity.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OAuth2ServerExamples\Entities;
|
||||||
|
|
||||||
|
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;
|
||||||
|
use League\OAuth2\Server\Entities\Traits\AccessTokenTrait;
|
||||||
|
use League\OAuth2\Server\Entities\Traits\EntityTrait;
|
||||||
|
use League\OAuth2\Server\Entities\Traits\TokenEntityTrait;
|
||||||
|
|
||||||
|
class AccessTokenEntity implements AccessTokenEntityInterface
|
||||||
|
{
|
||||||
|
use AccessTokenTrait, TokenEntityTrait, EntityTrait;
|
||||||
|
}
|
@ -3,39 +3,48 @@
|
|||||||
namespace OAuth2ServerExamples\Repositories;
|
namespace OAuth2ServerExamples\Repositories;
|
||||||
|
|
||||||
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;
|
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;
|
||||||
|
use League\OAuth2\Server\Entities\Interfaces\ClientEntityInterface;
|
||||||
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
|
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
|
||||||
|
use OAuth2ServerExamples\Entities\AccessTokenEntity;
|
||||||
|
|
||||||
class AccessTokenRepository implements AccessTokenRepositoryInterface
|
class AccessTokenRepository implements AccessTokenRepositoryInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Persists a new access token to permanent storage.
|
* @inheritdoc
|
||||||
*
|
|
||||||
* @param \League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface $accessTokenEntity
|
|
||||||
*/
|
*/
|
||||||
public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity)
|
public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity)
|
||||||
{
|
{
|
||||||
// TODO: Implement persistNewAccessToken() method.
|
// Some logic here to save the access token to a database
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Revoke an access token.
|
* @inheritdoc
|
||||||
*
|
|
||||||
* @param string $tokenId
|
|
||||||
*/
|
*/
|
||||||
public function revokeAccessToken($tokenId)
|
public function revokeAccessToken($tokenId)
|
||||||
{
|
{
|
||||||
// TODO: Implement revokeAccessToken() method.
|
// Some logic here to revoke the access token
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the access token has been revoked.
|
* @inheritdoc
|
||||||
*
|
|
||||||
* @param string $tokenId
|
|
||||||
*
|
|
||||||
* @return bool Return true if this token has been revoked
|
|
||||||
*/
|
*/
|
||||||
public function isAccessTokenRevoked($tokenId)
|
public function isAccessTokenRevoked($tokenId)
|
||||||
{
|
{
|
||||||
// TODO: Implement isAccessTokenRevoked() method.
|
return false; // Access token hasn't been revoked
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null)
|
||||||
|
{
|
||||||
|
$accessToken = new AccessTokenEntity();
|
||||||
|
$accessToken->setClient($clientEntity);
|
||||||
|
foreach ($scopes as $scope) {
|
||||||
|
$accessToken->addScope($scope);
|
||||||
|
}
|
||||||
|
$accessToken->setUserIdentifier($userIdentifier);
|
||||||
|
|
||||||
|
return $accessToken;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user