This repository has been archived by the owner on Mar 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
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 #39 from TomHAnderson/feature/oauth2server-validate
Validate OAuth2 server from Query resources
- Loading branch information
Showing
5 changed files
with
90 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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace ZF\OAuth2\Doctrine\Query; | ||
|
||
use Zend\ServiceManager\InitializerInterface; | ||
use Zend\ServiceManager\ServiceLocatorInterface; | ||
use ZF\OAuth2\Doctrine\Query\OAuth2ServerInterface; | ||
|
||
class OAuth2ServerInitializer implements InitializerInterface | ||
{ | ||
public function initialize($instance, ServiceLocatorInterface $serviceLocator) | ||
{ | ||
if ($instance instanceof OAuth2ServerInterface) { | ||
$oAuth2ServerFactory = $serviceLocator->getServiceLocator()->get('ZF\OAuth2\Service\OAuth2Server'); | ||
$oAuth2Server = $oAuth2ServerFactory(); | ||
$instance->setOAuth2Server($oAuth2Server); | ||
} | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
namespace ZF\OAuth2\Doctrine\Query; | ||
|
||
use OAuth2\Server as OAuth2Server; | ||
|
||
interface OAuth2ServerInterface | ||
{ | ||
public function setOAuth2Server(OAuth2Server $server); | ||
public function getOAuth2Server(); | ||
public function validateOAuth2($scope = 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,42 @@ | ||
<?php | ||
|
||
namespace ZF\OAuth2\Doctrine\Query; | ||
|
||
use OAuth2\Server as OAuth2Server; | ||
use OAuth2\Request as OAuth2Request; | ||
use ZF\ApiProblem\ApiProblem; | ||
|
||
trait OAuth2ServerTrait | ||
{ | ||
protected $oAuth2Server; | ||
|
||
public function setOAuth2Server(OAuth2Server $server) | ||
{ | ||
$this->oAuth2Server = $server; | ||
|
||
return $this; | ||
} | ||
|
||
public function getOAuth2Server() | ||
{ | ||
return $this->oAuth2Server; | ||
} | ||
|
||
public function validateOAuth2($scope = null) | ||
{ | ||
if (! $this->getOAuth2Server()->verifyResourceRequest( | ||
OAuth2Request::createFromGlobals(), | ||
$response = null, | ||
$scope | ||
)) { | ||
$error = $this->getOAuth2Server()->getResponse(); | ||
$parameters = $error->getParameters(); | ||
$detail = isset($parameters['error_description']) ? | ||
$parameters['error_description']: $error->getStatusText(); | ||
|
||
return new ApiProblem($error->getStatusCode(), $detail); | ||
} | ||
|
||
return true; | ||
} | ||
} |