当前位置: 首页 > 工具软件 > l-passport > 使用案例 >

laravel5.5 laravel/passport axios 一直返回 Unauthenticated 500

慕容俭
2023-12-01

场景

  • laravel/passport Consuming Your API With JavaScript 使用laravel/passport 访问自身的接口的时候 十分简单, 只是需要在 web middleware graoup 添加 \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class
    • 但是laravel5.5版本却有个bug ,导致axios访问会一直返回Unauthenticated 500
    • 环境重现
      • php7.2
      • laravel5.5
      • nginx
      • ubuntu16.04
      • “laravel/passport”: “~4.0”
      • 进行的laravel/passport的配置
        • config/auth.php api .driver= ‘passport’
        • app/Providers/AuthServiceProvider Passport::routes();
        • axios 默认配置
        • app/Http/Kernel.php web group middlware add \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,

Typically, if you want to consume your API from your JavaScript application, you would need to manually send an access token to the application and pass it with each request to your application. However, Passport includes a middleware that can handle this for you. All you need to do is add the CreateFreshApiToken middleware to your web middleware group:

分析

  • 尝试过laravel5.7 完全没有问题, 所以可能是版本问题
  • 有问题当然github了

解决

 类似资料: