php - Laravel HTTP basic authentication not working -
I am creating an API in Laravel and I am trying to use HTTP Basic Authentication. I created a user with an email / password combination of user@gmail.com: testpass
. I'm reaching an end point at the following URL for which authentication is required: https: //user@gmail.com: testpass@myapp.local/users/2
When I add the auth.basic
route filter on this route, I can successfully authenticate and access the user's details through the Auth
class, although this is a The API is, therefore I want to use Stateless HTTP Basic authentication, therefore I wrote my own filter:
// Once using our own filter filter and returning a consistent API response, the root :: filter ('basic.once', function ( ) {$ Result = Auth :: onceBasic (); if ($ result-> GetStatusCode () === 401) {// Unauthorized, return our own answer Returns: Answer: json (['message' => Bad Credentials'], ConfiG :: Receive ('status panic unauthorized'));} return result;});
No matter that, AUTH :: One time results
is always unauthorized here, even if the user name / password combination is sent to me I am living, it remains the same. Even if I convert Auth :: onceBasic ()
to Auth :: basic ()
into my filter, then it is still unauthorized.
I also do not know where to start debugging from my filter as essentially the auth.basic
filter as well as ship with Laravel, though With a little more code to prepare a compatible API output
From the official Larval document:
A note on FastGGI
If you are using PHP FastCGI, the HTTP Basic Authentication box can not work properly. The following lines should be added to your .htaccess file:
rewrite% {http: authorization} ^ (. +) $ RewriteRule * - [E = HTTP_AUTHORIZATION:% {http: authorization}]
I managed to resolve it myself in this way.
Comments
Post a Comment