Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to generate token getting handleAuthorizeRequest error #152

Open
rohini-knowlens opened this issue Aug 20, 2021 · 4 comments
Open

Comments

@rohini-knowlens
Copy link

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
Copy link
Collaborator

varp commented Aug 22, 2021

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

@rohini-knowlens
Copy link
Author

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

@rguillome
Copy link

rguillome commented May 10, 2022

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
Copy link

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

  • php 8.1
  • Yii2 , 2.0.47
  • filsh, v2.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants