Answer the question
In order to leave comments, you need to log in
Error when authorizing through VK. How to fix?
Good day. I do authorization through the social. networks via the yiisoft/yii2-authclient extension . I set up twitter and yadex, and the authorization went fine.
But the problem is that I can’t do it for VKontakte. I have added my clientId and clientSecret to the code below. I added to the config (I set up a twitter with a kernel in the same way):
'vkontakte' => [
'class' => 'yii\authclient\clients\VKontakte',
'clientId' => '*******',
'clientSecret' => '*************',
],
http://site.ru/auth/network/auth?authclient=vkontakte
http://site.ru/auth/network/auth?authclient=twitter
http://site.ru/auth/network/auth?authclient=yandex
array_shift() expects parameter 1 to be array, null given
{"error":"invalid_request","error_description":"redirect_uri is incorrect, check application redirect uri in the settings page"}
Answer the question
In order to leave comments, you need to log in
In general, he suffered with this problem. Perhaps it will help someone (I do not pretend to be the best solution):
I changed the urlManager'e link so that it looks like
site.ru/auth/network/vkontakte
instead
of site.ru/auth/network/auth?authclient=vkontakte
Plus I had to redefine one class. And voila!
class AuthAction extends BaseAuthAction {
protected function authOAuth2($client)
{
if ($client->getName() === 'vkontakte') {
$client->setReturnUrl(Yii::$app->urlManagerFrontend->createAbsoluteUrl(['/user/sign-in/oauth/vkontakte']));
}
return parent::authOAuth2($client);
}
}
From some version, the mandatory parameter v was introduced. In this case, it was enough to simply override the method.
/**
* @inheritdoc
*/
public function applyAccessTokenToRequest($request, $accessToken)
{
$data = $request->getData();
$data['v'] = '3.0';
$data['uids'] = $accessToken->getParam('user_id');
$data['access_token'] = $accessToken->getToken();
$request->setData($data);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question