E
E
E6APB2017-08-27 12:07:50
In contact with
E6APB, 2017-08-27 12:07:50

Laravel Socialite: why does VK say redirect_url is not the same?

I use Laravel Socialite and the provider for VK to it. My code:
Routing:

Route::get('vk', '[email protected]');

Route::get('vk/callback', '[email protected]');

Controller:
use SocialiteProviders\Manager\Config;

public function vk()
{
    $clientId = env('VKONTAKTE_KEY');
    $clientSecret = env('VKONTAKTE_SECRET');
    $redirectUrl = url('drivers/login/vk/callback');

    $config = new Config($clientId, $clientSecret, $redirectUrl);

    return \Socialite::with('vkontakte')
                                    ->setConfig($config)
                                    ->setScopes([])
                                    ->redirect();
}

public function vkCallback()
{
    $user = \Socialite::driver('vkontakte')->user();

    dd($user);
}

the vk() method works fine, but after redirecting to vkCallback, an error occurs, saying that the URLs do not match.

Client error: `POST https://oauth.vk.com/access_token` resulted in a `401 Unauthorized` response:
{"error":"invalid_grant","error_description":"redirect_uri is invalid, please pass same redirect_uri, you used in author (truncated...)

Why is that?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Shashenkov, 2017-08-27
@teknik2008

Have you tried to prolog?
Perhaps different.

D
dustdevil, 2018-04-24
@dustdevil

->setConfig($config) - the answer lies here. For some reason, the config is not pulled dynamically, but is still taken from the one set in config/services.php
The only option I came up with is to change the config itself:
Config::set([$this->service_key => ['client_id' => $ this->app_id, 'client_secret' => $this->app_key, 'redirect' => $this->redirect]]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question