mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-29 00:10:43 +05:30
Updated examples
This commit is contained in:
parent
5cba35456f
commit
5ca2152313
13
examples/src/Entities/AuthCodeEntity.php
Normal file
13
examples/src/Entities/AuthCodeEntity.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OAuth2ServerExamples\Entities;
|
||||||
|
|
||||||
|
use League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface;
|
||||||
|
use League\OAuth2\Server\Entities\Traits\AuthCodeTrait;
|
||||||
|
use League\OAuth2\Server\Entities\Traits\EntityTrait;
|
||||||
|
use League\OAuth2\Server\Entities\Traits\TokenEntityTrait;
|
||||||
|
|
||||||
|
class AuthCodeEntity implements AuthCodeEntityInterface
|
||||||
|
{
|
||||||
|
use EntityTrait, TokenEntityTrait, AuthCodeTrait;
|
||||||
|
}
|
12
examples/src/Entities/RefreshTokenEntity.php
Normal file
12
examples/src/Entities/RefreshTokenEntity.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OAuth2ServerExamples\Entities;
|
||||||
|
|
||||||
|
use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface;
|
||||||
|
use League\OAuth2\Server\Entities\Traits\EntityTrait;
|
||||||
|
use League\OAuth2\Server\Entities\Traits\RefreshTokenTrait;
|
||||||
|
|
||||||
|
class RefreshTokenEntity implements RefreshTokenEntityInterface
|
||||||
|
{
|
||||||
|
use RefreshTokenTrait, EntityTrait;
|
||||||
|
}
|
@ -4,38 +4,39 @@ namespace OAuth2ServerExamples\Repositories;
|
|||||||
|
|
||||||
use League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface;
|
use League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface;
|
||||||
use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface;
|
use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface;
|
||||||
|
use OAuth2ServerExamples\Entities\AuthCodeEntity;
|
||||||
|
|
||||||
class AuthCodeRepository implements AuthCodeRepositoryInterface
|
class AuthCodeRepository implements AuthCodeRepositoryInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Persists a new auth code to permanent storage.
|
* @inheritdoc
|
||||||
*
|
|
||||||
* @param \League\OAuth2\Server\Entities\Interfaces\AuthCodeEntityInterface $authCodeEntity
|
|
||||||
*/
|
*/
|
||||||
public function persistNewAuthCode(AuthCodeEntityInterface $authCodeEntity)
|
public function persistNewAuthCode(AuthCodeEntityInterface $authCodeEntity)
|
||||||
{
|
{
|
||||||
// TODO: Implement persistNewAuthCode() method.
|
// Some logic to persist the auth code to a database
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Revoke an auth code.
|
* @inheritdoc
|
||||||
*
|
|
||||||
* @param string $codeId
|
|
||||||
*/
|
*/
|
||||||
public function revokeAuthCode($codeId)
|
public function revokeAuthCode($codeId)
|
||||||
{
|
{
|
||||||
// TODO: Implement revokeAuthCode() method.
|
// Some logic to revoke the auth code in a database
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the auth code has been revoked.
|
* @inheritdoc
|
||||||
*
|
|
||||||
* @param string $codeId
|
|
||||||
*
|
|
||||||
* @return bool Return true if this code has been revoked
|
|
||||||
*/
|
*/
|
||||||
public function isAuthCodeRevoked($codeId)
|
public function isAuthCodeRevoked($codeId)
|
||||||
{
|
{
|
||||||
// TODO: Implement isAuthCodeRevoked() method.
|
return false; // The auth code has not been revoked
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function getNewAuthCode()
|
||||||
|
{
|
||||||
|
return new AuthCodeEntity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,38 +4,39 @@ namespace OAuth2ServerExamples\Repositories;
|
|||||||
|
|
||||||
use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface;
|
use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface;
|
||||||
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
|
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
|
||||||
|
use OAuth2ServerExamples\Entities\RefreshTokenEntity;
|
||||||
|
|
||||||
class RefreshTokenRepository implements RefreshTokenRepositoryInterface
|
class RefreshTokenRepository implements RefreshTokenRepositoryInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Create a new refresh token_name.
|
* @inheritdoc
|
||||||
*
|
|
||||||
* @param \League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface $refreshTokenEntityInterface
|
|
||||||
*/
|
*/
|
||||||
public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntityInterface)
|
public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntityInterface)
|
||||||
{
|
{
|
||||||
// TODO: Implement persistNewRefreshToken() method.
|
// Some logic to persist the refresh token in a database
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Revoke the refresh token.
|
* @inheritdoc
|
||||||
*
|
|
||||||
* @param string $tokenId
|
|
||||||
*/
|
*/
|
||||||
public function revokeRefreshToken($tokenId)
|
public function revokeRefreshToken($tokenId)
|
||||||
{
|
{
|
||||||
// TODO: Implement revokeRefreshToken() method.
|
// Some logic to revoke the refresh token in a database
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the refresh token has been revoked.
|
* @inheritdoc
|
||||||
*
|
|
||||||
* @param string $tokenId
|
|
||||||
*
|
|
||||||
* @return bool Return true if this token has been revoked
|
|
||||||
*/
|
*/
|
||||||
public function isRefreshTokenRevoked($tokenId)
|
public function isRefreshTokenRevoked($tokenId)
|
||||||
{
|
{
|
||||||
// TODO: Implement isRefreshTokenRevoked() method.
|
return false; // The refresh token has not been revoked
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function getNewRefreshToken()
|
||||||
|
{
|
||||||
|
return new RefreshTokenEntity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
src/Entities/Traits/AuthCodeTrait.php
Normal file
27
src/Entities/Traits/AuthCodeTrait.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace League\OAuth2\Server\Entities\Traits;
|
||||||
|
|
||||||
|
trait AuthCodeTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var null|string
|
||||||
|
*/
|
||||||
|
protected $redirectUri;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getRedirectUri()
|
||||||
|
{
|
||||||
|
return $this->redirectUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $uri
|
||||||
|
*/
|
||||||
|
public function setRedirectUri($uri)
|
||||||
|
{
|
||||||
|
$this->redirectUri = $uri;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user