diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index c8724f6b20..8260d1d572 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -82,6 +82,7 @@ use Alchemy\Phrasea\Core\Middleware\ApiApplicationMiddlewareProvider; use Alchemy\Phrasea\Core\Middleware\BasketMiddlewareProvider; use Alchemy\Phrasea\Core\Middleware\TokenMiddlewareProvider; use Alchemy\Phrasea\Core\Provider\ACLServiceProvider; +use Alchemy\Phrasea\Core\Provider\APIServiceProvider; use Alchemy\Phrasea\Core\Provider\AuthenticationManagerServiceProvider; use Alchemy\Phrasea\Core\Provider\BrowserServiceProvider; use Alchemy\Phrasea\Core\Provider\BorderManagerServiceProvider; @@ -218,6 +219,7 @@ class Application extends SilexApplication $this->register(new ApiApplicationMiddlewareProvider()); $this->register(new ACLServiceProvider()); + $this->register(new APIServiceProvider()); $this->register(new AuthenticationManagerServiceProvider()); $this->register(new BorderManagerServiceProvider()); $this->register(new BrowserServiceProvider()); diff --git a/lib/Alchemy/Phrasea/Controller/Api/Oauth2.php b/lib/Alchemy/Phrasea/Controller/Api/Oauth2.php index 2f34b02e79..f2923a4ce0 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/Oauth2.php +++ b/lib/Alchemy/Phrasea/Controller/Api/Oauth2.php @@ -31,10 +31,6 @@ class Oauth2 implements ControllerProviderInterface $controllers = $app['controllers_factory']; - $app['oauth'] = $app->share(function ($app) { - return new \API_OAuth2_Adapter($app); - }); - /** * AUTHORIZE ENDPOINT * @@ -43,7 +39,7 @@ class Oauth2 implements ControllerProviderInterface */ $authorize_func = function () use ($app) { $request = $app['request']; - $oauth2Adapter = $app['oauth']; + $oauth2Adapter = $app['oauth2-server']; $context = new Context(Context::CONTEXT_OAUTH2_NATIVE); $app['dispatcher']->dispatch(PhraseaEvents::PRE_AUTHENTICATE, new PreAuthenticate($request, $context)); @@ -156,7 +152,7 @@ class Oauth2 implements ControllerProviderInterface throw new HttpException(400, 'This route requires the use of the https scheme', null, ['content-type' => 'application/json']); } - $app['oauth']->grantAccessToken($request); + $app['oauth2-server']->grantAccessToken($request); ob_flush(); flush(); diff --git a/lib/Alchemy/Phrasea/Controller/Api/V1.php b/lib/Alchemy/Phrasea/Controller/Api/V1.php index bd80a1a082..458785d16f 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V1.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V1.php @@ -1971,10 +1971,9 @@ class V1 implements ControllerProviderInterface $app['dispatcher']->dispatch(PhraseaEvents::PRE_AUTHENTICATE, new PreAuthenticate($request, $context)); $app['dispatcher']->dispatch(PhraseaEvents::API_OAUTH2_START, new ApiOAuth2StartEvent()); - $oauth2_adapter = new \API_OAuth2_Adapter($app); - $oauth2_adapter->verifyAccessToken(); + $app['oauth2-server']->verifyAccessToken(); - if (null === $token = $app['repo.api-oauth-tokens']->find($oauth2_adapter->getToken())) { + if (null === $token = $app['repo.api-oauth-tokens']->find($app['oauth2-server']->getToken())) { throw new NotFoundHttpException('Provided token is not valid.'); } $app['session']->set('token', $token); @@ -1993,7 +1992,7 @@ class V1 implements ControllerProviderInterface } $app['authentication']->openAccount($oAuth2Account->getUser()); - $oauth2_adapter->rememberSession($app['session']); + $app['oauth2-server']->rememberSession($app['session']); $app['dispatcher']->dispatch(PhraseaEvents::API_OAUTH2_END, new ApiOAuth2EndEvent()); } diff --git a/lib/Alchemy/Phrasea/Core/Provider/APIServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/APIServiceProvider.php new file mode 100644 index 0000000000..6c65d2fa1e --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Provider/APIServiceProvider.php @@ -0,0 +1,29 @@ +share(function ($app) { + return new \API_OAuth2_Adapter($app); + }); + } + + public function boot(Application $app) + { + } +} diff --git a/lib/classes/API/OAuth2/Adapter.php b/lib/classes/API/OAuth2/Adapter.php index 9e556cfc6b..b5da9a0b08 100644 --- a/lib/classes/API/OAuth2/Adapter.php +++ b/lib/classes/API/OAuth2/Adapter.php @@ -80,9 +80,9 @@ class API_OAuth2_Adapter extends OAuth2 * @param Application $app * @return API_OAuth2_Adapter */ - public function __construct(Application $app) + public function __construct(Application $app, array $conf = []) { - parent::__construct(); + parent::__construct($conf); $this->app = $app; $this->params = []; }