How to extends AuthController
Closed this issue · 1 comments
Deleted user commented
Hello,
I want to extends AuthController to handle userinfo request, but don't know how to do that.
This is how I have tried:
<?php
namespace Test\Controller;
use ZF\OAuth2\Controller\AuthController;
use OAuth2\Server as OAuth2Server;
use ZF\OAuth2\Provider\UserId\UserIdProviderInterface;
class AuthOpenIdConnectController extends AuthController
{
public function __construct($serverFactory, UserIdProviderInterface $userIdProvider) {
parent::__construct($serverFactory, $userIdProvider);
}
/**
* Token Action (/userinfo)
*/
public function userinfoAction()
{
//implementation
}
}
in Test\config\module.config
return array(
...
'controllers' => array(
'factories' => array(
'Test\Controller\AuthOpenIdConnect' => 'Test\Factory\OpenIdConnectAuthControllerFactory',
),
....
<?php
namespace Test\Factory;
use OAuth2\Server as OAuth2Server;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Test\Controller\AuthOpenIdConnectController as AuthController;
class OpenIdConnectAuthControllerFactory implements FactoryInterface
{
/**
* @param ServiceLocatorInterface $controllers
* @return AuthController
*/
public function createService(ServiceLocatorInterface $controllers)
{
$services = $controllers->getServiceLocator()->get('ServiceManager');
// For BC, if the ZF\OAuth2\Service\OAuth2Server service returns an
// OAuth2\Server instance, wrap it in a closure.
$oauth2ServerFactory = $services->get('ZF\OAuth2\Service\OAuth2Server');
if ($oauth2ServerFactory instanceof OAuth2Server) {
$oauth2Server = $oauth2ServerFactory;
$oauth2ServerFactory = function () use ($oauth2Server) {
return $oauth2Server;
};
}
$authController = new AuthController(
$oauth2ServerFactory,
$services->get('ZF\OAuth2\Provider\UserId')
);
$config = $services->get('Config');
$authController->setApiProblemErrorResponse((isset($config['zf-oauth2']['api_problem_error_response'])
&& $config['zf-oauth2']['api_problem_error_response'] === true));
return $authController;
}
}
and in oauth2.local.php
<?php
return array(
...
'controllers' => array(
'factories' => array(
'ZF\OAuth2\Controller\Auth' => 'Test\Controller\AuthOpenIdConnect'
)
),
...
);
but it didn't work. How should I do it correctly? I'm pretty new to Zend, so I don't really know how.
Thanks.
Deleted user commented
silly me, the problem is in another part.