yii2-oauth2-server
yii2-oauth2-server copied to clipboard
Not able to generate token getting handleAuthorizeRequest error
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();
}
@rohini-knowlens Hi, which version of Yii and the package?
Yii version => 2.0.40 and filsh/yii2-oauth2-server => 2.1.0
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
?
@rohini-knowlens , Have you solved this problem? I have same problem in :
- php 8.1
- Yii2 , 2.0.47
- filsh, v2.1.1