Laravel Passport 500内部服务器错误

时间:2018-09-05 15:09:11

标签: laravel vue.js axios laravel-passport laragon

所以我用laravel护照,我遇到了问题。当我向AuthController @ login发出发布请求时,它给了我500个内部服务器错误。这就是我正在使用的

我将laragon与apache服务器和mysql一起用于环境。我可以毫无问题地向我的注册路由发出请求,但是我的登录路由一直失败。不确定我错过了什么

这是我的AuthController.php

public function login(Request $request)
{
    $http = new \GuzzleHttp\Client;

    try {
        $response = $http->post(config('services.passport.login_endpoint'), [
            'form_params' => [
                'grant_type' => 'password',
                'client_id' => config('services.passport.client_id'),
                'client_secret' => config('services.passport.client_secret'),
                'username' => $request->username,
                'password' => $request->password,
            ]
        ]);
        return $response->getBody();
    } catch (\GuzzleHttp\Exception\BadResponseException $e) {
        if ($e->getCode() === 400) {
            return response()->json('Invalid Request. Please enter a username or a password.', $e->getCode());
        } else if ($e->getCode() === 401) {
            return response()->json('Your credentials are incorrect. Please try again', $e->getCode());
        }
        return response()->json('Something went wrong on the server.', $e->getCode());
    }
}

这是我存储在.env文件中的变量

PASSPORT_LOGIN_ENDPOINT="http://traxit-backend2.test/oauth/token"
PASSPORT_CLIENT_ID=2
PASSPORT_CLIENT_SECRET=3xlUZVF1fP5fHOQgXAY2Vd7xrIsGjGNRagcMcfU5

这是我的api路由

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

Route::post('/login', 'AuthController@login');
Route::post('/register', 'AuthController@register');
Route::middleware('auth:api')->post('/logout', 'AuthController@logout');

这是日志即时通讯

  
      
  1. GuzzleHttp \ Exception \ RequestException->()C:\ laragon \ www \ traxit-backend2 \ vendor \ guzzlehttp \ guzzle \ src \ Handler \ CurlFactory.php:186
  2.   
  3. GuzzleHttp \ Handler \ CurlFactory-> createRejection()C:\ laragon \ www \ traxit-backend2 \ vendor \ guzzlehttp \ guzzle \ src \ Handler \ CurlFactory.php:149
  4.   
  5. GuzzleHttp \ Handler \ CurlFactory-> finishError()C:\ laragon \ www \ traxit-backend2 \ vendor \ guzzlehttp \ guzzle \ src \ Handler \ CurlFactory.php:102
  6.   
  7. GuzzleHttp \ Handler \ CurlFactory-> finish()C:\ laragon \ www \ traxit-backend2 \ vendor \ guzzlehttp \ guzzle \ src \ Handler \ CurlHandler.php:43
  8.   
  9. GuzzleHttp \ Handler \ CurlHandler-> __ invoke()C:\ laragon \ www \ traxit-backend2 \ vendor \ guzzlehttp \ guzzle \ src \ Handler \ Proxy.php:28
  10.   
  11. GuzzleHttp \ Handler \ Proxy-> GuzzleHttp \ Handler {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ guzzlehttp \ guzzle \ src \ Handler \ Proxy.php:51
  12.   
  13. GuzzleHttp \ Handler \ Proxy-> GuzzleHttp \ Handler {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ guzzlehttp \ guzzle \ src \ PrepareBodyMiddleware.php:66
  14.   
  15. GuzzleHttp \ PrepareBodyMiddleware-> __ invoke()C:\ laragon \ www \ traxit-backend2 \ vendor \ guzzlehttp \ guzzle \ src \ Middleware.php:30
  16.   
  17. GuzzleHttp \ Middleware-> GuzzleHttp {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ guzzlehttp \ guzzle \ src \ RedirectMiddleware.php:70
  18.   
  19. GuzzleHttp \ RedirectMiddleware-> __ invoke()C:\ laragon \ www \ traxit-backend2 \ vendor \ guzzlehttp \ guzzle \ src \ Middleware.php:60
  20.   
  21. GuzzleHttp \ Middleware-> GuzzleHttp {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ guzzlehttp \ guzzle \ src \ HandlerStack.php:67
  22.   
  23. GuzzleHttp \ HandlerStack-> __ invoke()C:\ laragon \ www \ traxit-backend2 \ vendor \ guzzlehttp \ guzzle \ src \ Client.php:277
  24.   
  25. GuzzleHttp \ Client-> transfer()C:\ laragon \ www \ traxit-backend2 \ vendor \ guzzlehttp \ guzzle \ src \ Client.php:125
  26.   
  27. GuzzleHttp \ Client-> requestAsync()C:\ laragon \ www \ traxit-backend2 \ vendor \ guzzlehttp \ guzzle \ src \ Client.php:131
  28.   
  29. GuzzleHttp \ Client-> request()C:\ laragon \ www \ traxit-backend2 \ vendor \ guzzlehttp \ guzzle \ src \ Client.php:89
  30.   
  31. GuzzleHttp \ Client-> __ call()C:\ laragon \ www \ traxit-backend2 \ app \ Http \ Controllers \ AuthController.php:22
  32.   
  33. App \ Http \ Controllers \ AuthController-> login()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Controller.php:54
  34.   
  35. call_user_func_array()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Controller.php:54
  36.   
  37. Illuminate \ Routing \ Controller-> callAction()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ ControllerDispatcher.php:45
  38.   
  39. Illuminate \ Routing \ ControllerDispatcher-> dispatch()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Route.php:212
  40.   
  41. Illuminate \ Routing \ Route-> runController()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Route.php:169
  42.   
  43. Illuminate \ Routing \ Route-> run()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Router.php:679
  44.   
  45. Illuminate \ Routing \ Router-> Illuminate \ Routing {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Pipeline.php:30
  46.   
  47. Illuminate \ Routing \ Pipeline-> Illuminate \ Routing {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Middleware \ SubstituteBindings.php:41
  48.   
  49. Illuminate \ Routing \ Middleware \ SubstituteBindings-> handle()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Pipeline \ Pipeline.php:151
  50.   
  51. Illuminate \ Pipeline \ Pipeline-> Illuminate \ Pipeline {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Pipeline.php:53
  52.   
  53. Illuminate \ Routing \ Pipeline-> Illuminate \ Routing {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Middleware \ ThrottleRequests.php:57
  54.   
  55. Illuminate \ Routing \ Middleware \ ThrottleRequests-> handle()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Pipeline \ Pipeline.php:151
  56.   
  57. Illuminate \ Pipeline \ Pipeline-> Illuminate \ Pipeline {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Pipeline.php:53
  58.   
  59. Illuminate \ Routing \ Pipeline-> Illuminate \ Routing {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Pipeline \ Pipeline.php:104
  60.   
  61. Illuminate \ Pipeline \ Pipeline-> then()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Router.php:681
  62.   
  63. Illuminate \ Routing \ Router-> runRouteWithinStack()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Router.php:656
  64.   
  65. Illuminate \ Routing \ Router-> runRoute()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Router.php:622
  66.   
  67. Illuminate \ Routing \ Router-> dispatchToRoute()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Router.php:611
  68.   
  69. Illuminate \ Routing \ Router-> dispatch()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Http \ Kernel.php:176
  70.   
  71. Illuminate \ Foundation \ Http \内核-> Illuminate \ Foundation \ Http {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Pipeline.php:30
  72.   
  73. Illuminate \ Routing \ Pipeline-> Illuminate \ Routing {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ barryvdh \ laravel-cors \ src \ HandleCors.php:36
  74.   
  75. Barryvdh \ Cors \ HandleCors-> handle()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Pipeline \ Pipeline.php:151
  76.   
  77. Illuminate \ Pipeline \ Pipeline-> Illuminate \ Pipeline {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Pipeline.php:53
  78.   
  79. Illuminate \ Routing \ Pipeline-> Illuminate \ Routing {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ fideloper \ proxy \ src \ TrustProxies.php:57
  80.   
  81. Fideloper \ Proxy \ TrustProxies-> handle()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Pipeline \ Pipeline.php:151
  82.   
  83. Illuminate \ Pipeline \ Pipeline-> Illuminate \ Pipeline {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Pipeline.php:53
  84.   
  85. Illuminate \ Routing \ Pipeline-> Illuminate \ Routing {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Http \ Middleware \ TransformsRequest.php:31
  86.   
  87. Illuminate \ Foundation \ Http \ Middleware \ TransformsRequest-> handle()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Pipeline \ Pipeline.php:151
  88.   
  89. Illuminate \ Pipeline \ Pipeline-> Illuminate \ Pipeline {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Pipeline.php:53
  90.   
  91. Illuminate \ Routing \ Pipeline-> Illuminate \ Routing {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Http \ Middleware \ TransformsRequest.php:31
  92.   
  93. Illuminate \ Foundation \ Http \ Middleware \ TransformsRequest-> handle()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Pipeline \ Pipeline.php:151
  94.   
  95. Illuminate \ Pipeline \ Pipeline-> Illuminate \ Pipeline {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Pipeline.php:53
  96.   
  97. Illuminate \ Routing \ Pipeline-> Illuminate \ Routing {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Http \ Middleware \ ValidatePostSize.php:27
  98.   
  99. Illuminate \ Foundation \ Http \ Middleware \ ValidatePostSize-> handle()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Pipeline \ Pipeline.php:151
  100.   
  101. Illuminate \ Pipeline \ Pipeline-> Illuminate \ Pipeline {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Pipeline.php:53
  102.   
  103. Illuminate \ Routing \ Pipeline-> Illuminate \ Routing {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Http \ Middleware \ CheckForMaintenanceMode.php:62
  104.   
  105. Illuminate \ Foundation \ Http \ Middleware \ CheckForMaintenanceMode-> handle()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Pipeline \ Pipeline.php:151
  106.   
  107. Illuminate \ Pipeline \ Pipeline-> Illuminate \ Pipeline {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Routing \ Pipeline.php:53
  108.   
  109. Illuminate \ Routing \ Pipeline-> Illuminate \ Routing {closure}()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Pipeline \ Pipeline.php:104
  110.   
  111. Illuminate \ Pipeline \ Pipeline-> then()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Http \ Kernel.php:151
  112.   
  113. Illuminate \ Foundation \ Http \ Kernel-> sendRequestThroughRouter()C:\ laragon \ www \ traxit-backend2 \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Http \ Kernel.php:116
  114.   
  115. Illuminate \ Foundation \ Http \ Kernel-> handle()C:\ laragon \ www \ traxit-backend2 \ public \ index.php:55
  116.   

1 个答案:

答案 0 :(得分:0)

此问题是我的services.passport配置文件中的services不存在。我把它放在我的services.php配置文件中。

'passport' => [
        'login_endpoint'  => env('TOKEN_LOGIN_ENDPOINT'),
        'client_id'    => env('TOKEN_CLIENT_ID'),
        'client_secret' => env('TOKEN_CLIENT_SECRET'),
    ],