Skip to content

Commit

Permalink
Merge pull request #33 from zf-fr/interfaces
Browse files Browse the repository at this point in the history
Add interfaces
  • Loading branch information
bakura10 committed Jul 31, 2015
2 parents cf66e20 + c28693d commit 656248b
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Server/AuthorizationServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @author Michaël Gallego <[email protected]>
* @licence MIT
*/
class AuthorizationServer implements EventManagerAwareInterface
class AuthorizationServer implements AuthorizationServerInterface, EventManagerAwareInterface
{
use EventManagerAwareTrait;

Expand Down
69 changes: 69 additions & 0 deletions src/Server/AuthorizationServerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/

namespace ZfrOAuth2\Server;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use ZfrOAuth2\Server\Entity\TokenOwnerInterface;
use ZfrOAuth2\Server\Exception\OAuth2Exception;

/**
* The authorization server main role is to create access tokens or refresh tokens
*/
interface AuthorizationServerInterface
{
/**
* Check if the authorization server supports this grant
*
* @param string $grant
* @return bool
*/
public function hasGrant($grant);

/**
* Check if the authorization server supports this response type
*
* @param string $responseType
* @return bool
*/
public function hasResponseType($responseType);

/**
* @param ServerRequestInterface $request
* @param TokenOwnerInterface|null $owner
* @return ResponseInterface
* @throws OAuth2Exception If no "response_type" could be found in the GET parameters
*/
public function handleAuthorizationRequest(ServerRequestInterface $request, TokenOwnerInterface $owner = null);

/**
* @param ServerRequestInterface $request
* @param TokenOwnerInterface|null $owner
* @return ResponseInterface
* @throws OAuth2Exception If no "grant_type" could be found in the POST parameters
*/
public function handleTokenRequest(ServerRequestInterface $request, TokenOwnerInterface $owner = null);

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
* @throws OAuth2Exception If no "token" is present
*/
public function handleRevocationRequest(ServerRequestInterface $request);
}
6 changes: 3 additions & 3 deletions src/Server/Grant/AuthorizationServerAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace ZfrOAuth2\Server\Grant;

use ZfrOAuth2\Server\AuthorizationServer;
use ZfrOAuth2\Server\AuthorizationServerInterface;

/**
* Interface for grant that need to have access to the authorization server
Expand All @@ -31,8 +31,8 @@ interface AuthorizationServerAwareInterface
/**
* Set the authorization server
*
* @param AuthorizationServer $authorizationServer
* @param AuthorizationServerInterface $authorizationServer
* @return void
*/
public function setAuthorizationServer(AuthorizationServer $authorizationServer);
public function setAuthorizationServer(AuthorizationServerInterface $authorizationServer);
}
6 changes: 3 additions & 3 deletions src/Server/Grant/AuthorizationServerAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace ZfrOAuth2\Server\Grant;

use ZfrOAuth2\Server\AuthorizationServer;
use ZfrOAuth2\Server\AuthorizationServerInterface;

/**
* @author Michaël Gallego <[email protected]>
Expand All @@ -27,14 +27,14 @@
trait AuthorizationServerAwareTrait
{
/**
* @var AuthorizationServer
* @var AuthorizationServerInterface
*/
protected $authorizationServer;

/**
* {@inheritDoc}
*/
public function setAuthorizationServer(AuthorizationServer $authorizationServer)
public function setAuthorizationServer(AuthorizationServerInterface $authorizationServer)
{
$this->authorizationServer = $authorizationServer;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Server/ResourceServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* @author Michaël Gallego <[email protected]>
* @licence MIT
*/
class ResourceServer
class ResourceServer implements ResourceServerInterface
{
/**
* @var TokenService
Expand Down
43 changes: 43 additions & 0 deletions src/Server/ResourceServerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/

namespace ZfrOAuth2\Server;

use Psr\Http\Message\ServerRequestInterface;
use ZfrOAuth2\Server\Entity\AccessToken;
use ZfrOAuth2\Server\Entity\Scope;

/**
* The resource server main role is to validate the access token and that its scope covers the
* requested resource
*
* Currently, the resource server only implements the Bearer token usage, as described in the
* RFC 6750 (http://tools.ietf.org/html/rfc6750)
*/
interface ResourceServerInterface
{
/**
* Get the access token
*
* @param ServerRequestInterface $request
* @param array|string|Scope[] $scopes
* @return AccessToken|null
* @throws Exception\InvalidAccessTokenException If given access token is invalid or expired
*/
public function getAccessToken(ServerRequestInterface $request, $scopes = []);
}

0 comments on commit 656248b

Please sign in to comment.