-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from zf-fr/evm
Move the EVM to the ZfrOAuth2
- Loading branch information
Showing
11 changed files
with
499 additions
and
4 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
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
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 |
---|---|---|
|
@@ -18,10 +18,14 @@ | |
|
||
namespace ZfrOAuth2\Server; | ||
|
||
use Zend\EventManager\EventManagerAwareInterface; | ||
use Zend\EventManager\EventManagerAwareTrait; | ||
use Zend\Http\Request as HttpRequest; | ||
use Zend\Http\Response as HttpResponse; | ||
use ZfrOAuth2\Server\Entity\Client; | ||
use ZfrOAuth2\Server\Entity\TokenOwnerInterface; | ||
use ZfrOAuth2\Server\Event\AuthorizationCodeEvent; | ||
use ZfrOAuth2\Server\Event\TokenEvent; | ||
use ZfrOAuth2\Server\Exception\OAuth2Exception; | ||
use ZfrOAuth2\Server\Grant\AuthorizationServerAwareInterface; | ||
use ZfrOAuth2\Server\Grant\GrantInterface; | ||
|
@@ -33,8 +37,10 @@ | |
* @author Michaël Gallego <[email protected]> | ||
* @licence MIT | ||
*/ | ||
class AuthorizationServer | ||
class AuthorizationServer implements EventManagerAwareInterface | ||
{ | ||
use EventManagerAwareTrait; | ||
|
||
/** | ||
* @var ClientService | ||
*/ | ||
|
@@ -162,6 +168,20 @@ public function handleAuthorizationRequest(HttpRequest $request, TokenOwnerInter | |
|
||
$response->getHeaders()->addHeaderLine('Content-Type', 'application/json'); | ||
|
||
$responseBody = json_decode($response->getContent(), true); | ||
|
||
$event = new AuthorizationCodeEvent($request, $responseBody, $response->getMetadata('authorizationCode')); | ||
$event->setTarget($this); | ||
|
||
if ($response->isSuccess()) { | ||
$this->getEventManager()->trigger(AuthorizationCodeEvent::EVENT_CODE_CREATED, $event); | ||
} else { | ||
$this->getEventManager()->trigger(AuthorizationCodeEvent::EVENT_CODE_FAILED, $event); | ||
} | ||
|
||
// We re-encode the content back into the response in case it changed | ||
$response->setContent(json_encode($event->getResponseBody())); | ||
|
||
return $response; | ||
} | ||
|
||
|
@@ -193,6 +213,20 @@ public function handleTokenRequest(HttpRequest $request, TokenOwnerInterface $ow | |
->addHeaderLine('Cache-Control', 'no-store') | ||
->addHeaderLine('Pragma', 'no-cache'); | ||
|
||
$responseBody = json_decode($response->getContent(), true); | ||
|
||
$event = new TokenEvent($request, $responseBody, $response->getMetadata('accessToken')); | ||
$event->setTarget($this); | ||
|
||
if ($response->isSuccess()) { | ||
$this->getEventManager()->trigger(TokenEvent::EVENT_TOKEN_CREATED, $event); | ||
} else { | ||
$this->getEventManager()->trigger(TokenEvent::EVENT_TOKEN_FAILED, $event); | ||
} | ||
|
||
// We re-encode the content back into the response in case it changed | ||
$response->setContent(json_encode($event->getResponseBody())); | ||
|
||
return $response; | ||
} | ||
|
||
|
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,94 @@ | ||
<?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\Event; | ||
|
||
use Zend\EventManager\Event; | ||
use Zend\Http\Request as HttpRequest; | ||
use Zend\Http\Response as HttpResponse; | ||
use ZfrOAuth2\Server\Entity\AuthorizationCode; | ||
|
||
/** | ||
* @author Michaël Gallego <[email protected]> | ||
* @licence MIT | ||
*/ | ||
class AuthorizationCodeEvent extends Event | ||
{ | ||
const EVENT_CODE_CREATED = 'authorizationCode.created'; | ||
const EVENT_CODE_FAILED = 'authorizationCode.failed'; | ||
|
||
/** | ||
* @var HttpRequest | ||
*/ | ||
protected $request; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $responseBody; | ||
|
||
/** | ||
* @var AuthorizationCode|null | ||
*/ | ||
protected $authorizationCode; | ||
|
||
/** | ||
* @param HttpRequest $request | ||
* @param array $responseBody | ||
* @param AuthorizationCode|null $authorizationCode | ||
*/ | ||
public function __construct(HttpRequest $request, array $responseBody, AuthorizationCode $authorizationCode = null) | ||
{ | ||
$this->request = $request; | ||
$this->responseBody = $responseBody; | ||
$this->authorizationCode = $authorizationCode; | ||
} | ||
|
||
/** | ||
* @return HttpRequest | ||
*/ | ||
public function getRequest() | ||
{ | ||
return $this->request; | ||
} | ||
|
||
/** | ||
* @param array $responseBody | ||
* @return void | ||
*/ | ||
public function setResponseBody(array $responseBody) | ||
{ | ||
$this->responseBody = $responseBody; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getResponseBody() | ||
{ | ||
return $this->responseBody; | ||
} | ||
|
||
/** | ||
* @return AuthorizationCode|null | ||
*/ | ||
public function getAuthorizationCode() | ||
{ | ||
return $this->authorizationCode; | ||
} | ||
} |
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,94 @@ | ||
<?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\Event; | ||
|
||
use Zend\EventManager\Event; | ||
use Zend\Http\Request as HttpRequest; | ||
use Zend\Http\Response as HttpResponse; | ||
use ZfrOAuth2\Server\Entity\AccessToken; | ||
|
||
/** | ||
* @author Michaël Gallego <[email protected]> | ||
* @licence MIT | ||
*/ | ||
class TokenEvent extends Event | ||
{ | ||
const EVENT_TOKEN_CREATED = 'token.created'; | ||
const EVENT_TOKEN_FAILED = 'token.failed'; | ||
|
||
/** | ||
* @var HttpRequest | ||
*/ | ||
protected $request; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $responseBody; | ||
|
||
/** | ||
* @var AccessToken|null | ||
*/ | ||
protected $accessToken; | ||
|
||
/** | ||
* @param HttpRequest $request | ||
* @param array $responseBody | ||
* @param AccessToken|null $accessToken | ||
*/ | ||
public function __construct(HttpRequest $request, array $responseBody, AccessToken $accessToken = null) | ||
{ | ||
$this->request = $request; | ||
$this->responseBody = $responseBody; | ||
$this->accessToken = $accessToken; | ||
} | ||
|
||
/** | ||
* @return HttpRequest | ||
*/ | ||
public function getRequest() | ||
{ | ||
return $this->request; | ||
} | ||
|
||
/** | ||
* @param array $responseBody | ||
* @return void | ||
*/ | ||
public function setResponseBody(array $responseBody) | ||
{ | ||
$this->responseBody = $responseBody; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getResponseBody() | ||
{ | ||
return $this->responseBody; | ||
} | ||
|
||
/** | ||
* @return AccessToken|null | ||
*/ | ||
public function getAccessToken() | ||
{ | ||
return $this->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
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
Oops, something went wrong.