From 564fcd4b093547b29363731f55d2e41973dd4332 Mon Sep 17 00:00:00 2001 From: Andy Heathershaw Date: Mon, 13 Aug 2018 14:25:56 +0100 Subject: [PATCH] #5: Added Laravel Socialite. The redirect to Facebook is now working. --- app/Http/Controllers/Auth/LoginController.php | 24 ++++ composer.json | 3 +- composer.lock | 127 +++++++++++++++++- config/services.php | 6 + routes/web.php | 4 + 5 files changed, 162 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 30fdda1..1161dd6 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -6,6 +6,7 @@ use App\Facade\Theme; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\AuthenticatesUsers; use Illuminate\Http\Request; +use Socialite; class LoginController extends Controller { @@ -61,4 +62,27 @@ class LoginController extends Controller 'info' => $request->session()->get('info') ]); } + + /** + * Redirect the user to the Facebook authentication page. + * + * @return \Illuminate\Http\Response + */ + public function redirectToFacebook() + { + return Socialite::driver('facebook')->redirect(); + } + + /** + * Obtain the user information from Facebook. + * + * @return \Illuminate\Http\Response + */ + public function handleFacebookCallback() + { + $user = Socialite::driver('facebook')->user(); + dd($user); + + // $user->token; + } } diff --git a/composer.json b/composer.json index c594bea..32bb1db 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "laravel/framework": "5.5.*", "rackspace/php-opencloud": "^1.16", "doctrine/dbal": "^2.5", - "aws/aws-sdk-php": "^3.19" + "aws/aws-sdk-php": "^3.19", + "laravel/socialite": "^3.0" }, "require-dev": { "filp/whoops": "~2.0", diff --git a/composer.lock b/composer.lock index ca1bee2..4497bb3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2469338aa47d9194dc0c44bc788fb070", + "content-hash": "7e1113109ae57d549a01afba28bdb219", "packages": [ { "name": "aws/aws-sdk-php", @@ -948,6 +948,68 @@ ], "time": "2018-03-30T13:29:30+00:00" }, + { + "name": "laravel/socialite", + "version": "v3.0.12", + "source": { + "type": "git", + "url": "https://github.com/laravel/socialite.git", + "reference": "b5f465847b1d637efa86bbfe2fc1c9d2bd12f60f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/socialite/zipball/b5f465847b1d637efa86bbfe2fc1c9d2bd12f60f", + "reference": "b5f465847b1d637efa86bbfe2fc1c9d2bd12f60f", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "~6.0", + "illuminate/contracts": "~5.4", + "illuminate/http": "~5.4", + "illuminate/support": "~5.4", + "league/oauth1-client": "~1.0", + "php": ">=5.4.0" + }, + "require-dev": { + "mockery/mockery": "~0.9", + "phpunit/phpunit": "~4.0|~5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + }, + "laravel": { + "providers": [ + "Laravel\\Socialite\\SocialiteServiceProvider" + ], + "aliases": { + "Socialite": "Laravel\\Socialite\\Facades\\Socialite" + } + } + }, + "autoload": { + "psr-4": { + "Laravel\\Socialite\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Laravel wrapper around OAuth 1 & OAuth 2 libraries.", + "keywords": [ + "laravel", + "oauth" + ], + "time": "2018-06-01T15:06:47+00:00" + }, { "name": "league/flysystem", "version": "1.0.45", @@ -1032,6 +1094,69 @@ ], "time": "2018-05-07T08:44:23+00:00" }, + { + "name": "league/oauth1-client", + "version": "1.7.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/oauth1-client.git", + "reference": "fca5f160650cb74d23fc11aa570dd61f86dcf647" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/oauth1-client/zipball/fca5f160650cb74d23fc11aa570dd61f86dcf647", + "reference": "fca5f160650cb74d23fc11aa570dd61f86dcf647", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^6.0", + "php": ">=5.5.0" + }, + "require-dev": { + "mockery/mockery": "^0.9", + "phpunit/phpunit": "^4.0", + "squizlabs/php_codesniffer": "^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "League\\OAuth1\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ben Corlett", + "email": "bencorlett@me.com", + "homepage": "http://www.webcomm.com.au", + "role": "Developer" + } + ], + "description": "OAuth 1.0 Client Library", + "keywords": [ + "Authentication", + "SSO", + "authorization", + "bitbucket", + "identity", + "idp", + "oauth", + "oauth1", + "single sign on", + "trello", + "tumblr", + "twitter" + ], + "time": "2016-08-17T00:36:58+00:00" + }, { "name": "mikemccabe/json-patch-php", "version": "0.1.0", diff --git a/config/services.php b/config/services.php index eab4683..b7c6039 100644 --- a/config/services.php +++ b/config/services.php @@ -14,6 +14,12 @@ return [ | */ + 'facebook' => [ + 'client_id' => env('FACEBOOK_CLIENT_ID'), + 'client_secret' => env('FACEBOOK_CLIENT_SECRET'), + 'redirect' => url('login/facebook/callback') + ], + 'gitea' => [ 'api_url' => 'https://apps.andysh.uk/api/v1', 'cache_time_seconds' => 3600, diff --git a/routes/web.php b/routes/web.php index f0357fe..1110f8d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -74,6 +74,10 @@ Route::group(['prefix' => 'install'], function () { Route::post('/database', 'InstallController@database')->name('install.database'); }); +// Social media SSO +Route::get('login/facebook', 'Auth\LoginController@redirectToFacebook')->name('login.facebook'); +Route::get('login/facebook/callback', 'Auth\LoginController@handleFacebookCallback')->name('login_callback.facebook'); + // Gallery Route::get('/', 'Gallery\DefaultController@index')->name('home'); Route::get('/activate/{token}', 'Auth\ActivateController@activate')->name('auth.activate');