php - How to add extra conditions to the authentication query in Laravel using HTTP Basic authentication? -
I found a route:
root :: find ('/', array ('First' = & gt; auth.basic ', function () {return response :: Jason (array (' name '=' gt; 'John Smith', 'age' => 42)); ));
What do I need to add active = 1
to the authentication query?
I know that I op :: effort ()
but I do not know how to use Auth :: basic ()
.
There are two ways to do this.
Modify 1 filter and use Ath :: Attempts ()
This is an easy way to go to app / filter.php
and on auth.basic change the entry
root :: filter ('auth.basic', function () {if (Auth :: check ()) return; // Already logged in (AUTH :: Attempt (array ('email' = & gt; Request :: getUser (), 'password' = & gt; Request :: getPassword (), 'active' => ; 1))} {return;} $ headers = array ('WWW-authentication' = & gt; 'basic'); return response :: forming ('invalid credentials.', 401, $ header););
This is basically what happens when the Laravel Guard class does when it is called Now is the "more elegant" way to do this though I do not know that it is really worth it in your case. I'm not even describing it in every detail. You can use Oath :: Basic (except for the 'active' part)
2. Extend Yourself
Auth :: extend
to extend Laravel Auth. $ Example = config: get ('auth.model'); $ Provider = new Illuminate \ Auth \ '\' auth \\ '(for example:' my_driver ', function) EloquentUserProvider (app :: create (' hash '), $ model); New migratory return ($ provider, app :: build ('session.store'));};
MyGuard
class illuminates \ orthore protector
and overrides the getBasicCredentials ()
method Could. Finally config / auth.php
set 'driver' = & gt; 'My_driver'
If you choose another method and need more help, then write a comment ...
Comments
Post a Comment