登录api路由始终返回200

时间:2018-07-19 15:36:47

标签: php laravel guzzle

我创建了一个Laravel API,该API被Vue前端使用。它在本地运行良好,我现在将其部署到登台服务器上,并且我的/login路由不起作用-无论凭据是否正确,它都返回200状态且没有响应文本,响应文本应包含access_token或JSON错误。

我的过程是通过git进行部署,使用composer设置依赖项,设置mySQL,配置.env文件,迁移数据库,运行php artisan passport:install,配置.env文件再次使用客户端密码和ID,使用邮递员创建tinker的用户,使用邮递员,我用必要的数据命中了端点/oauth/token,并成功获得了Bearer令牌,我可以使用Bearer令牌并获取相应的用户。通过Postman或Vue尝试登录时,我得到了前面所述的问题。

这是请求的“网络”标签。

enter image description here

AuthController.php

/user

Debug设置为true,我已经在日志中检查了,唯一的错误是这样:

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 json_decode((string) $response->getBody(), true);

     } 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());
     }
}

但是在搜索Google之后,我不知道这是否相关。我该如何更好地调试呢?有谁知道解决方案,任何指针将不胜感激。

0 个答案:

没有答案