A
A
Artem00712019-02-10 17:10:45
Laravel
Artem0071, 2019-02-10 17:10:45

Passport problem?

How to make this work properly ?
CreateFreshApiTokenconnected
Now, when I send a request to / test (that is, to "web"), authentication goes as it should:

Auth::check(); // true
Auth::user(); // User model

But when I send a request to /api/test (that is, to "api"), the authentication fails:
Auth::check(); // false
Auth::user(); // null

In cookies, everything seems to be sent:
Cookie: laravel_token=eyJpdiI6IjRnY1...
I just don’t understand what’s wrong

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin B., 2019-02-10
@Kostik_1993

Because you need to read the doc, it is also written there in an understandable language that CreateFreshApiToken generates a token and puts it in cuckoo. But this does not mean that he does everything for you. You need to get a token from the cookie at the front and send it with the behavior header.
You need to use this type

let bearer = Cookies.get('access_token');
if (bearer) {
    window.axios.defaults.headers.common['Authorization'] = bearer
}

S
snack008, 2019-04-06
@snack008

Konstatin gave you the right tip, which would be good for the doc to read.
But the less CreateFreshApiToken generates a token and puts it in ku-ku - right.
You will have to write a middleware that checks the x-csfr-token if the request comes from a site (api - oriented system). If an external site, then only through a token. The internet is full of information on how to do this. But since you are asking such a question, you do not understand how ouath2 is. I highly recommend spending 30 minutes of your life on this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question