PHP code example of laservici / authsocial

1. Go to this page and download the library: Download laservici/authsocial 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/ */

    

laservici / authsocial example snippets


'providers' => [
       ......
    // Application Service Providers...
       ......
       Laservici\Authsocial\AuthSocialServiceProvider::class,
],

'aliases' => [
    //  Class Aliases...
      .....
     'AuthSocial' => Laservici\Authsocial\Facades\AuthSocial::class,

    'github' => [
        'client_id'     => env('GITHUB_CLIENT_ID'),
        'client_secret' => env('GITHUB_CLIENT_SECRET'),
        'redirect'      => env('APP_URL').'/your-callback-url',
    ],




namespace App\Http\Controllers\Auth;

use Authsocial;

class AuthController extends Controller
{
    /**
     * Redirect the user to the GitHub authentication page.
     *
     * @return Response
     */
    public function redirectToProvider()
    {
        return Authsocial::driver('github')->redirect();
    }

    /**
     * Obtain the user information from GitHub.
     *
     * @return Response
     */
    public function handleProviderCallback()
    {
        $user = Authsocial::driver('github')->user();

        // $user->token;
    }
}

    return Authsocial::driver('github')
            ->scopes(['scope1', 'scope2'])->redirect();

   Route::get('auth/github', 'Auth\AuthController@redirectToProvider');
   Route::get('auth/github/callback', 'Auth\AuthController@handleProviderCallback');

  return Authsocial::driver('github')
            ->with(['hd' => 'example.com'])->redirect();

  return Authsocial::driver('github')->stateless()->user();

  $user = Authsocial::driver('github')->user();

// OAuth Two Providers
   $token = $user->token;
   $refreshToken = $user->refreshToken; // not always provided
   $expiresIn = $user->expiresIn;

// OAuth One Providers
   $token = $user->token;
   $tokenSecret = $user->tokenSecret;

// All Providers
   $user->getId();
   $user->getNickname();
   $user->getName();
   $user->getEmail();
   $user->getAvatar();

  $user = Authsocial::driver('github')->userFromToken($token);