filsh/yii2-oauth2-server

Module.php getRequest() function has an error after yii 2.0.13

anyeshe opened this issue · 5 comments

public function getRequest() { if(!$this->has('request')) { $this->set('request', Request::createFromGlobals()); } return $this->get('request'); }
this function call has() , but after yii 2.0.13 base/Module.php rewrite the has() function follow:
/** * {@inheritdoc} * * Since version 2.0.13, if a component isn't defined in the module, it will be looked up in the parent module. * The parent module may be the application. */ public function has($id, $checkInstance = false) { return parent::has($id, $checkInstance) || (isset($this->module) && $this->module->has($id, $checkInstance)); }
it's still return true . so when run the code an error product follow:
Argument 1 passed to OAuth2\Server::verifyResourceRequest() must be an instance of OAuth2\RequestInterface, instance of yii\web\Request given, called in /private/var/www/soho/allsec-local-yii/vendor/filsh/yii2-oauth2-server/Server.php on line 31
the function verifyResourceRequest function define follow:
public function verifyResourceRequest(\OAuth2\RequestInterface $request = null, \OAuth2\ResponseInterface $response = null, $scope = null) { if($request === null) { $request = $this->module->getRequest(); } parent::verifyResourceRequest($request, $response, $scope); }

My solution:

 'modules' => [
        'oauth2' => [
            'class' => 'filsh\yii2\oauth2server\Module',
   ...
            'components' => [
                'request' => [
                    'class' => Request::class,
                    'request' => $_REQUEST,
                    'server' => $_SERVER,
                    'headers' => WebHelper::getAllHeaders(),
                ],
            ],
        ],
    ],
varp commented

The solution offered by @Exsertin is not properly initialise the Request class. As example: underlying OAuth2 sever losing ability to validate client by HTTP Basic authorization.
So there is correct solution:

 'modules' => [
        'oauth2' => [
            'class' => 'filsh\yii2\oauth2server\Module',
...
            'components' => [
                'request' => static function () {
                    return filsh\yii2\oauth2server\Request::createFromGlobals();
                 },
            ],
      ],
]
varp commented

Fixed in the master branch. @mtangoo @anyeshe please, give me feedback, if it is actual for you

varp commented

Released version v2.0.1 to the Packagist!