Updated access token repository example

This commit is contained in:
Alex Bilbie 2016-04-09 15:09:22 +01:00
parent be9bd76f35
commit 5cba35456f
2 changed files with 36 additions and 14 deletions

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

View File

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