filsh / yii2-oauth2-server

A wrapper for implementing an OAuth2 Server(https://github.com/bshaffer/oauth2-server-php)
MIT License
332 stars 167 forks source link

Not able to generate token getting handleAuthorizeRequest error #152

Open rohini-knowlens opened 3 years ago

rohini-knowlens commented 3 years ago

Hi, I am trying to implement oauth2 for my rest API but getting this error in authorize action. Can anyone please help me on this.

Argument 2 passed to OAuth2\Server::handleAuthorizeRequest() must be an instance of OAuth2\ResponseInterface, instance of yii\web\Response given, called in vendor\filsh\yii2-oauth2-server\src\Server.php on line 59

Sample code public function actionAuthorize() {

    /*if (Yii::$app->getUser()->getIsGuest())
        return $this->redirect('login');*/

    $model = new LoginForm();
    $model->username = <username>;
    $model->password = <password>;
    if ($model->login()) {

    }
    else{
       //print_r($model->getErrors()); 
    }

    /** @var $module \filsh\yii2\oauth2server\Module */
    $module = Yii::$app->getModule('oauth2');
    //echo "<pre>"; print_r( $module);exit;
    $response = $module->getServer()->handleAuthorizeRequest(null, null, !Yii::$app->getUser()->getIsGuest(), Yii::$app->getUser()->getId());

    /** @var object $response \OAuth2\Response */
    Yii::$app->getResponse()->format = \yii\web\Response::FORMAT_JSON;

    return $response->getParameters();
}
varp commented 3 years ago

@rohini-knowlens Hi, which version of Yii and the package?

rohini-knowlens commented 3 years ago

Yii version => 2.0.40 and filsh/yii2-oauth2-server => 2.1.0

rguillome commented 2 years ago

Hi,

I think this comment in the \yii\base\Module class should be relevant for this issue :

     * 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));
        }

So the response is retrieved from the parent module \Yii\app ...

What do you think about resetting the response to the correct type in the filsh\yii2\oauth2server\Module if the type is \yii\web\Response ?

ahmadfadlydziljalal commented 1 year ago

@rohini-knowlens , Have you solved this problem? I have same problem in :