Integrating Laravel’s Auth with Sentinel

User authentication & authorization system is a common use case in a lot of apps. Thankfully Ryan Durham has a package that bootstraps resources needed for a fully functional authorization system in Laravel. You can install the package from packagist

 

"require": {
    "laravel/framework": "4.1.*",
    "rydurham/sentinel": "1.*"
},

 

You can check out the actual package on github https://github.com/rydurham/ Sentinel

The system is based on Cartalyst Sentry package https://github.com/cartalyst/sentry

Now this all works well. Unfortunately users logged in via sentry are not automatically logged on to Laravel’s native system as such the Auth facade is unusable.

This to me is a problem because I am more likely to switch out the sentry authentication system than I am to switch out the entire Laravel framework for any one particular project.

Thankfully Sentinel fires off events when a user logs in, logs out or registers. There are other events, but this are the ones we need.

As such we can listen to this events and update the native Laravel system to authenticate as well.

 

 

Make sure all the files are loaded on boot by Laravel. Now whenever there is a user action on Sentry, it will be immediately mirrored on Laravel’s Auth.

Till next time.

Happy coding.

 

 

 

 

 

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Published by

jchencha

API Engineer