PHP code example of larawizards / lara-oauth2-client

1. Go to this page and download the library: Download larawizards/lara-oauth2-client 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/ */

    

larawizards / lara-oauth2-client example snippets


return redirect()->route('login.sso');

return redirect()->route('oauth2.redirect');

Route::middleware(['oauth2.auth'])->group(function () {
    Route::get('/dashboard', function () {
        return view('dashboard');
    });
});

'user_mapping' => [
    'id' => 'oauth2_id',
    'email' => 'email',
    'name' => 'name',
    'first_name' => 'first_name',
    'last_name' => 'last_name',
    'avatar' => 'avatar',
],

Schema::table('users', function (Blueprint $table) {
    $table->string('oauth2_id')->nullable()->unique();
    $table->string('avatar')->nullable();
});

use Larawizards\LaraOAuth2Client\OAuth2Client;

$client = app(OAuth2Client::class);

// Get authorization URL
$authUrl = $client->getAuthorizationUrl();

// Get access token (after receiving authorization code)
$tokenData = $client->getAccessToken($code, $state);

// Get user info
$userInfo = $client->getUserInfo($tokenData['access_token']);

// Refresh token
$newTokenData = $client->refreshAccessToken($refreshToken);
bash
   php artisan lara-oauth2-client:install
   
bash
   php artisan migrate
   
bash
php artisan jetstream:install livewire
# or
php artisan jetstream:install inertia
bash
php artisan vendor:publish --tag=lara-oauth2-client-views