PHP code example of adamwathan / eloquent-oauth-l4

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


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

use \AdamWathan\EloquentOAuth\Exceptions\ApplicationRejectedException;
use \AdamWathan\EloquentOAuth\Exceptions\InvalidAuthorizationCodeException;

Route::get('facebook/login', function() {
    try {
        OAuth::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();
});

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

'providers' => array(
    // ...
    'AdamWathan\EloquentOAuthL4\EloquentOAuthServiceProvider',
    // ...
)

'aliases' => array(
    // ...
    'OAuth' => 'AdamWathan\EloquentOAuth\Facades\OAuth',
    // ...
)

'providers' => array(
    'facebook' => array(
        'client_id' => '12345678',
        'client_secret' => 'y0ur53cr374ppk3y',
        'redirect_uri' => URL::to('facebook/login'),
        'scope' => array(),
    )
)

'table' => 'social_login_tokens',

php artisan migrate:publish adamwathan/eloquent-oauth-l4
php artisan migrate