T
T
Tyoma Inagamov2020-01-27 18:55:55
In contact with
Tyoma Inagamov, 2020-01-27 18:55:55

Laravel Socialite: Why is access_token not being stored?

Hello,
I am Laravel Socialite Providersusing Вконтакте.

Laravel Socialite Providers
https://socialiteproviders.netlify.com/providers/v...


After I login, I can get all the user data as well as access_token, but if I reload the page, I get an error:
Client error: `POST https://oauth.vk.com/access_token` resulted in a `401 Unauthorized` response: {"error":"invalid_grant","error_description":"Code is invalid or expired."}


I have 3 ideas how to fix this:
  • sessions
  • Cookies
  • local storage

I tried to use them, but so far without success.

Code if needed:
1. routes/api.php
Route::get('intermediate-path', function(){
        $user = Socialite::driver('vkontakte')->user();

        $user_check = User::where('vk_id', '=', $user->id)->first();
        if ($user_check === null) {
            DB::insert('insert into users (vk_id, name, email) values (?, ?, ?)', [
                $user->id, $user->name, $user->email
            ]);

            echo "created";

        } else {
            echo "logged in";
        }
    });


2.Config/Services.php
'vkontakte' => [
    clientId = env('VKONTAKTE_KEY');
    clientSecret = env('VKONTAKTE_SECRET');
    redirectUrl = 'http://localhost:8000/api/auth/intermediate-path';
],


3. vendor/socialiteproviders/vkontakte/Provider.php
https://github.com/SocialiteProviders/VKontakte/bl...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin B., 2020-01-27
@Kostik_1993

Because the token is one-time. You must remember not him, but the user who enters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question