Information is difficult to find, in part because the OAuth2-server package for Laravel provides its own OAuth solution, which is most of the search results.
I think the best answer is to write your own YoutubeProvider for Socialite. Here is the tutorial: https://medium.com/laravel-news/adding-auth-providers-to-laravel-socialite-ca0335929e42#.6bn8i2wz4
It will be a pain to change Socialite to get started with update tokens, so I think the best route would be for YoutubeProvider to have an additional call to the new getRefreshToken function at the end of the existing getAccessToken function. Modify access and update tokens to store the extracted token in the database, because Socialite will not give you access to the update token to save it in the helper / controller class.
Create a Tokens model and a database table and save both access tokens and updated ones where relevant to the user model.
When you write the YoutubeService helper, he will have to try to make an API call with an access token and know to update it with the update token if he receives an error message that it has expired / is invalid.
The Google API library for PHP seems to handle this automatically with $client->setAccessType("offline") : https://developers.google.com/api-client-library/php/auth/web-app
but as soon as you start using update tokens for something other than Google, you will still write this code if the new provider also does not have a library. On the other hand, this library has a service specifically for Youtube, so it should handle all the API calls on Youtube that you might need. I'm not quite sure how the use of this library will be combined with Socialite, since Socialite seems to already do a lot of what this library does. You might end up creating some kind of redundant authorization in your YoutubeService class if you really don't want to start the setup.
Perhaps you should consider removing Socialite from the whole equation and using the Google library when it comes to their services.
Brynn bateman
source share