PHP code example of peal / laravel-social-login

1. Go to this page and download the library: Download peal/laravel-social-login library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

peal / laravel-social-login example snippets


$ php artisan vendor:publish

 Which provider or tag's files would you like to publish?:
  [0 ] Publish files from all providers and tags listed below
  [1 ] Provider: Facade\Ignition\IgnitionServiceProvider
  [2 ] Provider: Fideloper\Proxy\TrustedProxyServiceProvider
  [3 ] Provider: Illuminate\Foundation\Providers\FoundationServiceProvider
  [4 ] Provider: Illuminate\Mail\MailServiceProvider
  [5 ] Provider: Illuminate\Notifications\NotificationServiceProvider
  [6 ] Provider: Illuminate\Pagination\PaginationServiceProvider
  [7 ] Provider: Laravel\Tinker\TinkerServiceProvider
  [8 ] Provider: peal\socialLogin\LoginServiceProvider
  [9 ] Tag: flare-config
  [10] Tag: ignition-config
  [11] Tag: laravel-errors
  [12] Tag: laravel-mail
  [13] Tag: laravel-notifications
  [14] Tag: laravel-pagination
 > 8



return [
    'facebook' => [
        'app_id' => env('FACEBOOK_APP_ID'), //Don't change
        'app_secret' => env('FACEBOOK_APP_SECRET'), //Don't change
        'default_graph_version' => 'v2.6',
        'call_back_url' => 'http://localhost:8000/facebook-success', //Put your production call back url
        'scope' => [
            'email'
        ]
    ],
    'google' => [
        'application_name' => 'your-application-name',
        'client_id' => env('GOOGLE_CLIENT_ID'), //Don't change
        'client_secret' => env('GOOGLE_CLIENT_SECRET'), //Don't change
        'redirect_url' => 'http://localhost:8000/google-success', //Put your production redirect url
        'scope' => [
            'https://www.googleapis.com/auth/plus.me',
            'https://www.googleapis.com/auth/userinfo.email',
            'https://www.googleapis.com/auth/userinfo.profile',
        ]
    ],
    'github' => [
        'client_id' => env('GITHUB_CLIENT_ID'), //Don't change
        'client_secret' => env('GITHUB_CLIENT_SECRET'), //Don't change
        'authorize_url' => 'https://github.com/login/oauth/authorize',
        'token_url' => 'https://github.com/login/oauth/access_token',
        'api_url_base' => 'https://api.github.com/',
        'call_back_url' => 'http://localhost:8000/gitloginsuccess' //Put your production call back url
    ],
];

peal\socialLogin\LoginServiceProvider::class,

'FacebookLogin' => peal\socialLogin\Facades\FacebookLogin::class,

'GoogleLogin' => peal\socialLogin\Facades\GoogleLogin::class,

'GithubLogin' => peal\socialLogin\Facades\GithubLogin::class,
 
    Route::get('gitauthorize', function(){

        GithubLogin::getClientId();
        GithubLogin::getRedirectUri();
        return GithubLogin::getAuthorizeURL();
    });


    Route::get('gitloginsuccess', function(Request $request){
        $access_token = GithubLogin::getAccessToken($request);

        //Save this information into your database user table
        return GithubLogin::gitHubApiCall($access_token);
    });


    Route::get('facebookLogin', function(){
        FacebookLogin::getCallBackUrl();
        FacebookLogin::getScope();
        $login_url = FacebookLogin::getLoginUrl();
        return redirect($login_url);
    });


    Route::get('facebook-success', function(){
        //Save this information into your database user table
        return FacebookLogin::getOAuth2Client();
    });


    Route::get('googleLogin', function(){
        GoogleLogin::getScopes();
        return GoogleLogin::gotoAuthUrl();
    });


    Route::get('google-success', function(Request $request){
        
        if ($request->has('code') && empty($request->get('state'))) {
            //return GoogleLogin::getAccessToken(trim($request->get('code')));

            //Save this information into your database user table
            return $userinfo = GoogleLogin::clientLogin(trim($request->get('code')));
        }    
    });