Download the PHP package lcmaquino/youtubechannel without Composer
On this page you can find all versions of the php package lcmaquino/youtubechannel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lcmaquino/youtubechannel
More information about lcmaquino/youtubechannel
Files in lcmaquino/youtubechannel
Package youtubechannel
Short Description YouTubeChannel adds to Laravel the service provider for OAuth 2.0 authentication with YouTube Google account.
License GPL-3.0-or-later
Homepage https://github.com/lcmaquino/youtubechannel
Informations about the package youtubechannel
Introduction
YouTubeChannel adds to Laravel the service provider for OAuth 2.0 authentication with YouTube Google account.
It was created based on GoogleOAuth2 that is a Laravel package for OAuth 2.0 authentication with Google account.
Features
- The same features of GoogleOAuth2;
- Check if an user is subscribed on a given YouTube channel;
- Get some YouTube channel statistics: subscription count, views count and videos count.
For more information about Google OAuth 2.0, please see https://developers.google.com/identity/protocols/oauth2/web-server
Installation
Laravel should automatically include Lcmaquino\YouTubeChannel\YouTubeChannelProvider
as a service provider and include YouTubeChannel
as an alias for Lcmaquino\YouTubeChannel\Facades\YouTubeChannel::class
.
It can be done manually editing config/app.php
to look like:
Configuration
Before using YouTubeChannel, you need to set up an OAuth 2.0 client ID. The OAuth 2.0 client will provide a client id, a client secret, and a redirect uri for your application. These parameters and the youtube channel id should be placed in your .env
Laravel configuration file.
It will be loaded by your application when reading the file config/googleoauth2.php
:
Routing
Create two routes in routes/web.php
:
Create app/Http/Controllers/Auth/LoginController.php
and edit like this:
When you hit the route login/youtube
it will redirect your request to
Google authentication page. Google authentication will ask user
for permission and then hit your callback route login/youtube/callback
.
YouTubeChannel comes with a YouTubeChannel facade. So you could edit app/Http/Controllers/Auth/LoginController.php
like this:
Optional Parameters
To include any optional OAuth 2.0 parameters in the request, call the with
method with an associative array:
Access Scopes
The scopes are used by Google to limit your application access to the user account data.
Use the scopes
method to set your scopes. The defaults are openid
, email
and https://www.googleapis.com/auth/youtube.readonly
.
Read more about YouTube Data API scopes.
Stateless Authentication
The stateless
method disable session state verification.
Retrieving User Details
Once you have an authenticated $user
, you can get more details about the user:
Retrieving User Details From A Token
You can retrieve user details from a valid access $token
using the
getUserFromToken
method:
Refreshing token
The access token expires periodically. So you need to get a new one.
You can get this using the refreshUserToken
method:
You should pay attetion to keep the user $refresh_token
on your application.
If you lose it, then you can't get a new access token. In that case, the user
has to log in again when the current access token expires.
You will notice that refresh token is not always provided on Google authentication.
You can force Google to do so using the with
method (see Optional Parameters):
Revoking token
If you need to invalidate the access token and the refresh token, you can revoke
them using the revokeToken
method:
Tips
- You can use a valid access token or refresh token as
$token
. - Remeber to revoke the token when the user decides to sign out/remove their data from your application.
- Keep in mind that the user always can revoke their token on https://myaccount.google.com/permissions.
License
YouTubeChannel is open-sourced software licensed under the GPL v3.0 or later.
All versions of youtubechannel with dependencies
illuminate/http Version ^6.0|^7.0|^8.0
illuminate/support Version ^6.0|^7.0|^8.0
lcmaquino/googleoauth2 Version ^1.0.5