https://github.com/zfcampus/zf-oauth2を自分のアプリケーションで動作させようとしています (主に、apigility をインストールしており、zf-oauth2 が付属しているため)。
最後のセクションを読んでいて、保護するように書かれています。次のコードを使用するだけです(たとえば、コントローラーの上部で):
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).
ただし、 $this->server は何らかの形で注入する必要があります。しかし、私はどのように、そして何を注入するかを見つけることができないようです. リンクをクリックして AuthController.php を表示すると、ページが見つかりました...
編集: Tom と Ujjwal のおかげで、一歩近づいたと思います。
私のコントローラーでは、次のようになりました。
use ZF\OAuth2\Controller\AuthController;
class BaseController extends AuthController
{
}
私の Module.php では、次のように OAuth2Server を挿入してみます。
public function getServiceConfig()
{
return array(
'factories' => array(
'\Stand\Controller\BaseController' => function ($sm) {
$cls = new BaseController($sm->get('ZF\OAuth2\Service\OAuth2Server'));
return $cls;
},
)
);
}
しかし、ページをレンダリングしようとすると、挿入がキャッチされません。私は得る
キャッチ可能な致命的なエラー: ZF\OAuth2\Controller\AuthController::__construct() に渡される引数 1 は、OAuth2\Server のインスタンスである必要があります
ご意見をお聞かせください!
ありがとう