M
M
MaikMain2018-04-27 00:10:42
Yii
MaikMain, 2018-04-27 00:10:42

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' => '*************',
                ],

I have links here on this page (This is all displayed on the site.ru/login page):
http://site.ru/auth/network/auth?authclient=vkontakte
http://site.ru/auth/network/auth?authclient=twitter
http://site.ru/auth/network/auth?authclient=yandex

In the settings of the VK application, there is such a form: The
5ae23daf38436290208366.png
question is what you need to enter in the "Trusted redirect URI" field.
For example, for Yandex, it was necessary to specify the link site.ru/auth/network/auth?authclient=yandex
But VK says that "A trusted redirect URI that will be transmitted during OAuth authorization. Must contain a protocol. Cannot contain URL parameters, fragments, and relative paths". The contact doesn't even save links that have a GET parameter.
And if:
1. Do not write anything in this field, then an error appears:
array_shift() expects parameter 1 to be array, null given

And it refers to the file: " vendor\yiisoft\yii2-authclient\clients\VKontakte.php "
2. site.ru/auth/network/auth - same as in point #1
3. site.ru/auth/network
4 .site.ru/auth 5. site.ru/login This
error is displayed when you write items 3, 4, 5:
{"error":"invalid_request","error_description":"redirect_uri is incorrect, check application redirect uri in the settings page"}

What should I write?
Thank you very much in advance))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jiimka, 2018-05-02
@MaikMain

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

I
imlegend, 2019-01-18
@imlegend

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 question

Ask a Question

731 491 924 answers to any question