Skip to content

Commit 656248b

Browse files
committed
Merge pull request #33 from zf-fr/interfaces
Add interfaces
2 parents cf66e20 + c28693d commit 656248b

File tree

6 files changed

+120
-8
lines changed

6 files changed

+120
-8
lines changed

src/Server/AuthorizationServer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* @author Michaël Gallego <mic.gallego@gmail.com>
4040
* @licence MIT
4141
*/
42-
class AuthorizationServer implements EventManagerAwareInterface
42+
class AuthorizationServer implements AuthorizationServerInterface, EventManagerAwareInterface
4343
{
4444
use EventManagerAwareTrait;
4545

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/*
3+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14+
*
15+
* This software consists of voluntary contributions made by many individuals
16+
* and is licensed under the MIT license.
17+
*/
18+
19+
namespace ZfrOAuth2\Server;
20+
21+
use Psr\Http\Message\ResponseInterface;
22+
use Psr\Http\Message\ServerRequestInterface;
23+
use ZfrOAuth2\Server\Entity\TokenOwnerInterface;
24+
use ZfrOAuth2\Server\Exception\OAuth2Exception;
25+
26+
/**
27+
* The authorization server main role is to create access tokens or refresh tokens
28+
*/
29+
interface AuthorizationServerInterface
30+
{
31+
/**
32+
* Check if the authorization server supports this grant
33+
*
34+
* @param string $grant
35+
* @return bool
36+
*/
37+
public function hasGrant($grant);
38+
39+
/**
40+
* Check if the authorization server supports this response type
41+
*
42+
* @param string $responseType
43+
* @return bool
44+
*/
45+
public function hasResponseType($responseType);
46+
47+
/**
48+
* @param ServerRequestInterface $request
49+
* @param TokenOwnerInterface|null $owner
50+
* @return ResponseInterface
51+
* @throws OAuth2Exception If no "response_type" could be found in the GET parameters
52+
*/
53+
public function handleAuthorizationRequest(ServerRequestInterface $request, TokenOwnerInterface $owner = null);
54+
55+
/**
56+
* @param ServerRequestInterface $request
57+
* @param TokenOwnerInterface|null $owner
58+
* @return ResponseInterface
59+
* @throws OAuth2Exception If no "grant_type" could be found in the POST parameters
60+
*/
61+
public function handleTokenRequest(ServerRequestInterface $request, TokenOwnerInterface $owner = null);
62+
63+
/**
64+
* @param ServerRequestInterface $request
65+
* @return ResponseInterface
66+
* @throws OAuth2Exception If no "token" is present
67+
*/
68+
public function handleRevocationRequest(ServerRequestInterface $request);
69+
}

src/Server/Grant/AuthorizationServerAwareInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
namespace ZfrOAuth2\Server\Grant;
2020

21-
use ZfrOAuth2\Server\AuthorizationServer;
21+
use ZfrOAuth2\Server\AuthorizationServerInterface;
2222

2323
/**
2424
* Interface for grant that need to have access to the authorization server
@@ -31,8 +31,8 @@ interface AuthorizationServerAwareInterface
3131
/**
3232
* Set the authorization server
3333
*
34-
* @param AuthorizationServer $authorizationServer
34+
* @param AuthorizationServerInterface $authorizationServer
3535
* @return void
3636
*/
37-
public function setAuthorizationServer(AuthorizationServer $authorizationServer);
37+
public function setAuthorizationServer(AuthorizationServerInterface $authorizationServer);
3838
}

src/Server/Grant/AuthorizationServerAwareTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
namespace ZfrOAuth2\Server\Grant;
2020

21-
use ZfrOAuth2\Server\AuthorizationServer;
21+
use ZfrOAuth2\Server\AuthorizationServerInterface;
2222

2323
/**
2424
* @author Michaël Gallego <mic.gallego@gmail.com>
@@ -27,14 +27,14 @@
2727
trait AuthorizationServerAwareTrait
2828
{
2929
/**
30-
* @var AuthorizationServer
30+
* @var AuthorizationServerInterface
3131
*/
3232
protected $authorizationServer;
3333

3434
/**
3535
* {@inheritDoc}
3636
*/
37-
public function setAuthorizationServer(AuthorizationServer $authorizationServer)
37+
public function setAuthorizationServer(AuthorizationServerInterface $authorizationServer)
3838
{
3939
$this->authorizationServer = $authorizationServer;
4040
}

src/Server/ResourceServer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* @author Michaël Gallego <mic.gallego@gmail.com>
3434
* @licence MIT
3535
*/
36-
class ResourceServer
36+
class ResourceServer implements ResourceServerInterface
3737
{
3838
/**
3939
* @var TokenService
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/*
3+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14+
*
15+
* This software consists of voluntary contributions made by many individuals
16+
* and is licensed under the MIT license.
17+
*/
18+
19+
namespace ZfrOAuth2\Server;
20+
21+
use Psr\Http\Message\ServerRequestInterface;
22+
use ZfrOAuth2\Server\Entity\AccessToken;
23+
use ZfrOAuth2\Server\Entity\Scope;
24+
25+
/**
26+
* The resource server main role is to validate the access token and that its scope covers the
27+
* requested resource
28+
*
29+
* Currently, the resource server only implements the Bearer token usage, as described in the
30+
* RFC 6750 (http://tools.ietf.org/html/rfc6750)
31+
*/
32+
interface ResourceServerInterface
33+
{
34+
/**
35+
* Get the access token
36+
*
37+
* @param ServerRequestInterface $request
38+
* @param array|string|Scope[] $scopes
39+
* @return AccessToken|null
40+
* @throws Exception\InvalidAccessTokenException If given access token is invalid or expired
41+
*/
42+
public function getAccessToken(ServerRequestInterface $request, $scopes = []);
43+
}

0 commit comments

Comments
 (0)