I'm writing an Laravel (5.7 with dev-master framework) app for internal use in my school and I'm using their CAS server for authentication, but I want to check if the user is already registered in my own database.
I already implemented CAS login with https://github.com/subfission/cas.
I don't know if I should integrate CAS with the "native" Laravel auth (and I don't even know how to do it) or write a middleware or something like that (don't know how to do it either :P).
ps: english isn't my native language, so go easy with any writing errors pls
Aright, just checked their wiki and damn! It's quiet simple; after installing package you need to add two brand new middlewares to your app/Http/Kernel.php
at the end of $routeMiddlewares
property:
protected $routeMiddleware = [
//snap
'cas.auth' => \Subfission\Cas\Middleware\CASAuth::class,
'cas.guest' => \Subfission\Cas\Middleware\RedirectCASAuthenticated::class,
];
Good, now run php artisan vendor:publish --provider=Subfission\Cas\CasServiceProvider
so cas.php
config file will be added to config
folder. open it and enter your school's CAS configs.
Very good, now all you have to do is using cas.auth
middleware when you need CAS-authentication:
//web.php
Route::get('user/profile','UserController@profile')->middleware('cas.auth');
this middleware simply checks if current user is logged in on CAS server (continue to controller) or user is not logged in on CAS server (redirect to CAS server login page & redirect back on authentication successful).
Good Luck.