title: Using ZF2 Oauth2
body: <p>I'm trying to get <a href="https://github.com/zfcampus/zf-oauth2" rel="nofollow">https://github.com/zfcampus/zf-oauth2</a> working with my Application (mainly because I have installed apigility and zf-oauth2 comes with it).</p>
  
  <p>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):</p>
  
  <pre><code>if (!$this-&gt;server-&gt;verifyResourceRequest(OAuth2Request::createFromGlobals())) {
      // Not authorized return 401 error
      $this-&gt;getResponse()-&gt;setStatusCode(401);
      return;
  }
  // where $this-&gt;server is an instance of OAuth2\Server (see the AuthController.php).
  </code></pre>
  
  <p>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...</p>
  
  <p>Edit:
  Thanks to Tom and  Ujjwal, I think I am one step closer.</p>
  
  <p>In my controller, now I have the following:</p>
  
  <pre><code>use ZF\OAuth2\Controller\AuthController;
  
  class BaseController extends AuthController
  {
  
  }
  </code></pre>
  
  <p>In my Module.php, I try injecting OAuth2Server as such:</p>
  
  <pre><code>public function getServiceConfig()
  {
      return array(
         'factories' =&gt; array(
              '\Stand\Controller\BaseController' =&gt;  function ($sm) {
                  $cls = new BaseController($sm-&gt;get('ZF\OAuth2\Service\OAuth2Server'));
                  return $cls;
              },
          )
      );
  }
  </code></pre>
  
  <p>But, when I tried to render the page, it is not catching my inject. I get </p>
  
  <blockquote>
    <p>Catchable fatal error: Argument 1 passed to ZF\OAuth2\Controller\AuthController::__construct() must be an instance of OAuth2\Server</p>
  </blockquote>
  
  <p>Please advice!</p>
  
  <p>Thanks</p>