Last Updated: February 25, 2016
·
3.337K
· bretterer

Extending Laravel Auth drivers

If you have ever wanted to build an auth driver from Laravel but didn't know where to start (like me), here are the first steps.

Build yourself a workbench package with
php artisan workbench vendor/package --resources

and this will create you a base package.

In the boot of the packageServiceProvider.php file, add the following lines.

\Auth::extend('driver_name', function() {
     return new Guard(new Providers\PackageUserProvider, \App::make('session'));
 });

This will allow you to change your auth driver in the config to the new driver_name

Create your new UserProvider which should implement the UserProviderInterface. The Auth::attempt() call uses the methods retrieveByCredentials where you need to return a new User object, but then calls validateCredentials where you take the user object and verify that it is a valid user login.

For a full tutorial on how to do this, you can check out the blog post that I wrote up at http://goo.gl/WmGlP1 as well as the package that I created which uses stormpath auth within Laravel.