Using ZF2 Oauth2

依然范特西╮ 提交于 2019-12-08 07:48:53

问题


I'm trying to get https://github.com/zfcampus/zf-oauth2 working with my Application (mainly because I have installed apigility and zf-oauth2 comes with it).

I'm reading the very last section and it says to protect, I just simply use the following code (for instance, at the top of a controller):

if (!$this->server->verifyResourceRequest(OAuth2Request::createFromGlobals())) {
    // Not authorized return 401 error
    $this->getResponse()->setStatusCode(401);
    return;
}
// where $this->server is an instance of OAuth2\Server (see the AuthController.php).

However, $this->server has to be injected somehow. But, I can't seem to find how and what to inject. By clicking on the link to see AuthController.php, I get a page out found...

Edit: Thanks to Tom and Ujjwal, I think I am one step closer.

In my controller, now I have the following:

use ZF\OAuth2\Controller\AuthController;

class BaseController extends AuthController
{

}

In my Module.php, I try injecting OAuth2Server as such:

public function getServiceConfig()
{
    return array(
       'factories' => array(
            '\Stand\Controller\BaseController' =>  function ($sm) {
                $cls = new BaseController($sm->get('ZF\OAuth2\Service\OAuth2Server'));
                return $cls;
            },
        )
    );
}

But, when I tried to render the page, it is not catching my inject. I get

Catchable fatal error: Argument 1 passed to ZF\OAuth2\Controller\AuthController::__construct() must be an instance of OAuth2\Server

Please advice!

Thanks

来源:https://stackoverflow.com/questions/23996243/using-zf2-oauth2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!