From d8b6e2047e2de93953a628962ac1728d55ac7be7 Mon Sep 17 00:00:00 2001 From: German Lena Date: Wed, 6 Jan 2016 11:57:18 -0300 Subject: [PATCH] updated to be compatible with laravel 5.2 --- README.md | 36 +++++++++++++++++++++++- src/Auth0/Login/Auth0User.php | 9 ++++++ src/Auth0/Login/LaravelSessionStore.php | 2 +- src/Auth0/Login/LoginServiceProvider.php | 11 ++------ 4 files changed, 48 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d1a483d0..cf19aeb4 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,44 @@ Check our docs page to get a complete guide on how to install it in an existing > If you find something wrong in our docs, PR are welcome in our docs repo: https://github.com/auth0/docs +###Laravel 5.2 + +####Routes +Your routes need to be in the `web` routes group, otherwise it will not be able to use the session storage: + +``` +Route::group(['middleware' => ['web']], function () { + + Route::get('/auth0/callback', '\Auth0\Login\Auth0Controller@callback'); + + Route::get('/', function () { + + if (Auth::check()) dd('LOGGED IN',Auth::user()); + + return view('welcome'); + + }); +}); +``` + +####Auth setup + +In your `config/auth.php` file update the providers to use the `auth0` driver: + +``` +... + 'providers' => [ + 'users' => [ + 'driver' => 'auth0', + ], + ], +... +``` ##Laravel Compatibility -The last version (2.x) targets Laravel 5 compatibility. +The 2.x branch targets Laravel 5.0 and 5.1 compatibility. +The 3.x branch targets Laravel 5.2 compatibility. If you are working with an older version (Laravel 4.x) you need to point to composer.json to the version 1.0.* diff --git a/src/Auth0/Login/Auth0User.php b/src/Auth0/Login/Auth0User.php index 0a07669e..8743cb98 100644 --- a/src/Auth0/Login/Auth0User.php +++ b/src/Auth0/Login/Auth0User.php @@ -22,6 +22,15 @@ public function getAuthIdentifier() { return $this->userInfo["user_id"]; } + /** + * Get id field name. + * + * @return string + */ + public function getAuthIdentifierName() { + return 'id'; + } + /** * Get the password for the user. * diff --git a/src/Auth0/Login/LaravelSessionStore.php b/src/Auth0/Login/LaravelSessionStore.php index 4b9eaaf2..51ac2ae9 100644 --- a/src/Auth0/Login/LaravelSessionStore.php +++ b/src/Auth0/Login/LaravelSessionStore.php @@ -18,7 +18,7 @@ public function set($key, $value) { Session::put($key_name, $value); } - public function get($key, $default=false) { + public function get($key, $default=null) { $key_name = $this->getSessionKeyName($key); return Session::get($key_name, $default); diff --git a/src/Auth0/Login/LoginServiceProvider.php b/src/Auth0/Login/LoginServiceProvider.php index e6f9898a..35e079b2 100644 --- a/src/Auth0/Login/LoginServiceProvider.php +++ b/src/Auth0/Login/LoginServiceProvider.php @@ -22,15 +22,10 @@ class LoginServiceProvider extends ServiceProvider { */ public function boot() { - \Auth::extend('auth0', function($app) { - - // Let the container build the repository for us - $userRepository = \App::make('\Auth0\Login\Contract\Auth0UserRepository'); - - $provider = new Auth0UserProvider($userRepository); - - return new \Illuminate\Auth\Guard($provider, $app['session.store']); + \Auth::provider('auth0', function($app, array $config) { + $userRepository = \App::make(\Auth0\Login\Contract\Auth0UserRepository::class); + return new Auth0UserProvider($userRepository); }); $this->publishes([