Laravel and Passport, random errors 401

I am writing a one-page web application.

I use Vue.js in the interface and Laravel in the backend.

I have enabled Passport Token Authentication, and I get an Authentication Token Transfer

var login_data = { client_id : 2, client_secret : "SECRET_KEY", grant_type : "password", username : "mail", password : "pass" } 

To this endpoint of the passport is http: // IPADDRESS / oauth / token . Then I authenticate my AJAX requests, including this header

 { 'Authorization': 'Bearer ' + ACC_TOKEN } 

In most cases, everything works fine, but sometimes I get 401 unauthorized . Usually, if I just do it again, the request passes.

I removed the VerifyCsrfToken from Kernel.php and also added an API route to the exceptions, so I don't think the problem is.

The frequency of the error seems to vary from network to network, that is, when connected to certain networks, it almost never occurs, sometimes it is constant.

I honestly have no idea why this is happening.

+5
source share
1 answer

My problem was in PROJECTDIR / vendor / lcobucci / jwt / src / Signer / Rsa.php.

Here the openssl function (openssl_get_publickey) sometimes returns something wrong, even though the certificate is valid.

I could not find a real solution.

My hack now just changes the code to always return 1.

This does not change the way the token token works, but it removes the Rsa check and 401 errors caused by such a malfunction.

+2
source

Source: https://habr.com/ru/post/1266212/


All Articles