-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stanimir Stoyanov
committed
May 8, 2016
0 parents
commit dd1da15
Showing
43 changed files
with
2,874 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
/** | ||
* @author Alex Bilbie <[email protected]> | ||
* @copyright Copyright (c) Alex Bilbie | ||
* @license http://mit-license.org/ | ||
* | ||
* @link https://github.com/thephpleague/oauth2-server | ||
*/ | ||
|
||
namespace Phalcon2Rest\Components\Oauth2\Entities; | ||
|
||
use League\OAuth2\Server\Entities\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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
/** | ||
* @author Alex Bilbie <[email protected]> | ||
* @copyright Copyright (c) Alex Bilbie | ||
* @license http://mit-license.org/ | ||
* | ||
* @link https://github.com/thephpleague/oauth2-server | ||
*/ | ||
|
||
namespace Phalcon2Rest\Components\Oauth2\Entities; | ||
|
||
use League\OAuth2\Server\Entities\ClientEntityInterface; | ||
use League\OAuth2\Server\Entities\Traits\ClientTrait; | ||
use League\OAuth2\Server\Entities\Traits\EntityTrait; | ||
|
||
class ClientEntity implements ClientEntityInterface | ||
{ | ||
use EntityTrait, ClientTrait; | ||
|
||
public function setName($name) | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
public function setRedirectUri($uri) | ||
{ | ||
$this->redirectUri = $uri; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
/** | ||
* @author Alex Bilbie <[email protected]> | ||
* @copyright Copyright (c) Alex Bilbie | ||
* @license http://mit-license.org/ | ||
* | ||
* @link https://github.com/thephpleague/oauth2-server | ||
*/ | ||
|
||
namespace Phalcon2Rest\Components\Oauth2\Entities; | ||
|
||
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; | ||
use League\OAuth2\Server\Entities\Traits\EntityTrait; | ||
use League\OAuth2\Server\Entities\Traits\RefreshTokenTrait; | ||
|
||
class RefreshTokenEntity implements RefreshTokenEntityInterface | ||
{ | ||
use RefreshTokenTrait, EntityTrait; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* @author Alex Bilbie <[email protected]> | ||
* @copyright Copyright (c) Alex Bilbie | ||
* @license http://mit-license.org/ | ||
* | ||
* @link https://github.com/thephpleague/oauth2-server | ||
*/ | ||
|
||
namespace Phalcon2Rest\Components\Oauth2\Entities; | ||
|
||
use League\OAuth2\Server\Entities\ScopeEntityInterface; | ||
use League\OAuth2\Server\Entities\Traits\EntityTrait; | ||
|
||
class ScopeEntity implements ScopeEntityInterface | ||
{ | ||
use EntityTrait; | ||
|
||
public function jsonSerialize() | ||
{ | ||
return $this->getIdentifier(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
* @author Alex Bilbie <[email protected]> | ||
* @copyright Copyright (c) Alex Bilbie | ||
* @license http://mit-license.org/ | ||
* | ||
* @link https://github.com/thephpleague/oauth2-server | ||
*/ | ||
|
||
namespace Phalcon2Rest\Components\Oauth2\Entities; | ||
|
||
use League\OAuth2\Server\Entities\UserEntityInterface; | ||
|
||
class UserEntity implements UserEntityInterface | ||
{ | ||
private $user; | ||
|
||
public function __construct($userArray) | ||
{ | ||
$this->user = $userArray; | ||
} | ||
|
||
/** | ||
* Return the user's identifier. | ||
* | ||
* @return mixed | ||
*/ | ||
public function getIdentifier() | ||
{ | ||
return $this->user['id']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Phalcon2Rest\Components\Oauth2; | ||
|
||
use League\OAuth2\Server\Entities\AccessTokenEntityInterface; | ||
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class GenerateResult implements \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface { | ||
|
||
public function setAccessToken(AccessTokenEntityInterface $accessToken) | ||
{ | ||
// TODO: Implement setAccessToken() method. | ||
} | ||
|
||
public function setRefreshToken(RefreshTokenEntityInterface $refreshToken) | ||
{ | ||
// TODO: Implement setRefreshToken() method. | ||
} | ||
|
||
public function generateHttpResponse(ResponseInterface $response) | ||
{ | ||
// TODO: Implement generateHttpResponse() method. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* @author Alex Bilbie <[email protected]> | ||
* @copyright Copyright (c) Alex Bilbie | ||
* @license http://mit-license.org/ | ||
* | ||
* @link https://github.com/thephpleague/oauth2-server | ||
*/ | ||
|
||
namespace Phalcon2Rest\Components\Oauth2\Repositories; | ||
|
||
use League\OAuth2\Server\Entities\AccessTokenEntityInterface; | ||
use League\OAuth2\Server\Entities\ClientEntityInterface; | ||
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; | ||
use Phalcon2Rest\Components\Oauth2\Entities\AccessTokenEntity; | ||
|
||
class AccessTokenRepository implements AccessTokenRepositoryInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity) | ||
{ | ||
// Some logic here to save the access token to a database | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function revokeAccessToken($tokenId) | ||
{ | ||
// Some logic here to revoke the access token | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isAccessTokenRevoked($tokenId) | ||
{ | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* @author Alex Bilbie <[email protected]> | ||
* @copyright Copyright (c) Alex Bilbie | ||
* @license http://mit-license.org/ | ||
* | ||
* @link https://github.com/thephpleague/oauth2-server | ||
*/ | ||
|
||
namespace Phalcon2Rest\Components\Oauth2\Repositories; | ||
|
||
use League\OAuth2\Server\Repositories\ClientRepositoryInterface; | ||
use Phalcon\Security; | ||
use Phalcon2Rest\Components\Oauth2\Entities\ClientEntity; | ||
use Phalcon\Di\FactoryDefault as Di; | ||
use Phalcon2Rest\Models\Clients; | ||
|
||
class ClientRepository implements ClientRepositoryInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getClientEntity($clientIdentifier, $grantType, $clientSecret = null, $mustValidateSecret = true) | ||
{ | ||
$di = new Di(); | ||
/** @var Security $security */ | ||
$security = $di->getShared('security'); | ||
$client = Clients::query() | ||
->where("id = :id:") | ||
->bind([ | ||
'id' => $clientIdentifier | ||
]) | ||
->limit(1) | ||
->execute() | ||
->toArray(); | ||
$correctDetails = false; | ||
if (count($client) === 1) { | ||
$client = current($client); | ||
if ($mustValidateSecret) { | ||
|
||
if ($security->checkHash($clientSecret, $client['secret'])) { | ||
$correctDetails = true; | ||
} else { | ||
$security->hash(rand()); | ||
|
||
} | ||
} else { | ||
$correctDetails = true; | ||
} | ||
} else { | ||
// prevent timing attacks | ||
$security->hash(rand()); | ||
} | ||
|
||
if ($correctDetails) { | ||
$clientEntity = new ClientEntity(); | ||
$clientEntity->setIdentifier($clientIdentifier); | ||
$clientEntity->setName($client['name']); | ||
$clientEntity->setRedirectUri($client['redirect_url']); | ||
return $clientEntity; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* @author Alex Bilbie <[email protected]> | ||
* @copyright Copyright (c) Alex Bilbie | ||
* @license http://mit-license.org/ | ||
* | ||
* @link https://github.com/thephpleague/oauth2-server | ||
*/ | ||
|
||
namespace Phalcon2Rest\Components\Oauth2\Repositories; | ||
|
||
use League\OAuth2\Server\Entities\RefreshTokenEntityInterface; | ||
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface; | ||
use Phalcon2Rest\Components\Oauth2\Entities\RefreshTokenEntity; | ||
|
||
class RefreshTokenRepository implements RefreshTokenRepositoryInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntityInterface) | ||
{ | ||
// Some logic to persist the refresh token in a database | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function revokeRefreshToken($tokenId) | ||
{ | ||
// Some logic to revoke the refresh token in a database | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isRefreshTokenRevoked($tokenId) | ||
{ | ||
return false; // The refresh token has not been revoked | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getNewRefreshToken() | ||
{ | ||
return new RefreshTokenEntity(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* @author Alex Bilbie <[email protected]> | ||
* @copyright Copyright (c) Alex Bilbie | ||
* @license http://mit-license.org/ | ||
* | ||
* @link https://github.com/thephpleague/oauth2-server | ||
*/ | ||
|
||
namespace Phalcon2Rest\Components\Oauth2\Repositories; | ||
|
||
use League\OAuth2\Server\Entities\ClientEntityInterface; | ||
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface; | ||
use Phalcon2Rest\Components\Oauth2\Entities\ScopeEntity; | ||
|
||
class ScopeRepository implements ScopeRepositoryInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getScopeEntityByIdentifier($scopeIdentifier) | ||
{ | ||
$scopes = [ | ||
'basic' => [ | ||
'description' => 'Basic details about you', | ||
], | ||
'email' => [ | ||
'description' => 'Your email address', | ||
], | ||
]; | ||
|
||
if (array_key_exists($scopeIdentifier, $scopes) === false) { | ||
return; | ||
} | ||
|
||
$scope = new ScopeEntity(); | ||
$scope->setIdentifier($scopeIdentifier); | ||
|
||
return $scope; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function finalizeScopes( | ||
array $scopes, | ||
$grantType, | ||
ClientEntityInterface $clientEntity, | ||
$userIdentifier = null | ||
) { | ||
return $scopes; | ||
} | ||
} |
Oops, something went wrong.