简体   繁体   中英

Laravel and Passport, random 401 errors

I'm writing a single page web application.

I'm using Vue.js in the frontend and Laravel in the backend.

I included Passport token authentication and I'm getting the auth token sending

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

To this Passport endpoint http://IPADDRESS/oauth/token . Then I authenticate my AJAX requests including this header

{ 'Authorization': 'Bearer ' + ACC_TOKEN }

Most of the time everything works fine but sometimes I get 401 unauthorized . Usually, if I simply do it again the request goes through.

I removed the VerifyCsrfToken middleware from Kernel.php and also added the API route to the exceptions so I don't think that's the problem.

The frequency the error appears seems to change from network to network, meaning when connected to certain networks it almost never happens while sometimes it's constant.

I honestly have no idea why this happens.

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

Here an openssl function (openssl_get_publickey) sometimes returns something wrong despite the certificate being valid.

I did not manage to find a real solution.

My hack for now is simply changing the code to always return 1.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM