PHP code example of adamwathan / eloquent-oauth-l5

1. Go to this page and download the library: Download adamwathan/eloquent-oauth-l5 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/ */

    

adamwathan / eloquent-oauth-l5 example snippets


// Redirect to Facebook for authorization
Route::get('facebook/authorize', function() {
    return SocialAuth::authorize('facebook');
});

// Facebook redirects here after authorization
Route::get('facebook/login', function() {
    
    // Automatically log in existing users
    // or create a new user if necessary.
    SocialAuth::login('facebook');

    // Current user is now available via Auth facade
    $user = Auth::user();

    return Redirect::intended();
});

'providers' => [
    // ...
    AdamWathan\EloquentOAuthL5\EloquentOAuthServiceProvider::class,
    // ...
]

'aliases' => [
    // ...
    'SocialAuth' => AdamWathan\EloquentOAuth\Facades\OAuth::class,
    // ...
]

'providers' => [
    'facebook' => [
        'client_id' => '12345678',
        'client_secret' => 'y0ur53cr374ppk3y',
        'redirect_uri' => 'https://example.com/facebook/login'),
        'scope' => [],
    ]
]

// config/eloquent-oauth.php
return [
    'model' => User::class,
    'table' => 'oauth_identities',
    'providers' => [
        'facebook' => [ /* ... */],
        'google' => [ /* ... */],
        'gumroad' => [
            'client_id' => env('GUMROAD_CLIENT_ID'),
            'client_secret' => env('GUMROAD_CLIENT_SECRET'),
            'redirect_uri' => env('GUMROAD_REDIRECT_URI'),
            'scope' => ['view_sales'],
        ],
    ],
];

class MySocialAuthServiceProvider extends EloquentOAuthServiceProvider
{
    protected function getProviderLookup()
    {
        // Merge the default providers if you like, or override entirely
        // to skip loading those providers completely.
        return array_merge($this->providerLookup, [
            'gumroad' => GumroadProvider::class
        ]);
    }
}

Route::get('facebook/authorize', function() {
    return SocialAuth::authorize('facebook');
});

use SocialNorm\Exceptions\ApplicationRejectedException;
use SocialNorm\Exceptions\InvalidAuthorizationCodeException;

Route::get('facebook/login', function() {
    try {
        SocialAuth::login('facebook');
    } catch (ApplicationRejectedException $e) {
        // User rejected application
    } catch (InvalidAuthorizationCodeException $e) {
        // Authorization was attempted with invalid
        // code,likely forgery attempt
    }

    // Current user is now available via Auth facade
    $user = Auth::user();

    return Redirect::intended();
});

SocialAuth::login('facebook', function($user, $details) {
    $user->nickname = $details->nickname;
    $user->name = $details->full_name;
    $user->profile_image = $details->avatar;
    $user->save();
});

      'scope' => ['public_profile'],
   

        SocialAuth::login('facebook', function($user, $details) (
            $user->gender = $details->raw()['gender'];
            $user->save();
        });