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();
});
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
]);
}
}
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();
});