A
A
Artem00712018-12-29 13:00:03
Laravel
Artem0071, 2018-12-29 13:00:03

Why does Laravel Passport work so weird?

I made a vue application and installed Laravel Passport
access_token, but for some reason, when I send a request with it, it gives a 401 error. After some googling, I found out that if you add to route'middleware' => 'auth:api', it gives a normal result, but the paths stop working if the user is not authorized (cap)
After some more googling and even searching beyond the first page of Google !! I found out that if you add this code to the api controller:

public function __construct()
    {
        \Auth::shouldUse('api');
    }

In this case, the token will be checked only if it is passed.
Actually the question is why when I go through the paths api/*laravel does not use the 'api' defender by default and can this be fixed somehow?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kuznetsov, 2018-12-29
@dima9595

It is not always necessary to validate tokens, for example for public information. In fact, you can send all routes to one global middleware auth: api and you will be happy

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question