M
M
mixejuxix2019-07-22 12:03:11
Laravel
mixejuxix, 2019-07-22 12:03:11

How to make csrf protection for api requests?

Hi, tell me, how to make protection from csrf for API routes?
I have a nuxt SPA application on the front, with authorization via api Route::group(['middleware' => 'auth:api'])
Everything is clear for the admin - when authorizing by login and password, he receives an api_token, which I save in the session
But how to be there I want to make a form that the guest must fill out, without authorization at all? How to make protection from csrf?
Should I make some kind of ajax request to get the csrf token or what?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin B., 2019-07-22
@Kostik_1993

CSRF has nothing to do with it. It's not made for antispam sake
Antispam - I hope you highlighted that word above.

A
Andrey Suha, 2019-07-22
@andreysuha

Can skip cross-domain requests only from the domain on which the front is spinning? If not suitable, then make such an intermediary only for the form route

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question