Dan*_*ark 5 php passport.js laravel-5
这与 Laravel 5.4 及其 Passport 密码授予有关。
\n\n我有获取 access_token 供用户使用的路线,效果完全正常。
\n\n如果当前访问令牌过期,我还有一个刷新令牌的路线。
\n\n当我使用 Postman 到达路线时
\n\nhttp://192.168.10.10/refresh\nRun Code Online (Sandbox Code Playgroud)\n\n我得到这个有效的返回:
\n\n"data": {\n "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOi...deleting most of it.",\n "expires_in": 600\n}\nRun Code Online (Sandbox Code Playgroud)\n\n但是,当我通过浏览器点击路由时,通过以下代码使用 axios:
\n\nlet headers = { \'Content-type\': \'application/json\' }\nreturn axios.post("http://192.168.10.10/refresh", {headers: headers}).then(res => {\n if (res) return res;\n }).catch(err => {\n if (err) return err.response;\n });\nRun Code Online (Sandbox Code Playgroud)\n\n我收到 HTTP 500 错误状态代码。
\n\n我也在跟踪 laravel 日志中的错误,这是堆栈跟踪。
\n\n[2017-08-30 07:21:41] local.ERROR:GuzzleHttp\\Exception\\ClientException:客户端错误:POST http://192.168.10.10/oauth/token导致400 Bad Request响应:\n{"error":"invalid_request","message":"请求缺少必需的参数,包括无效的参数值,(被截断...)\n 在 /home/vagrant/Code/work/vendorgraphs-api/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
此错误的另一部分是它可能是格式错误的值。
\n\n对我来说没有意义,我已经尝试了从直接从 PHP 代码发出curl 请求以及使用 http_query_builder 功能的所有方法。
\n\nCache-Control \xe2\x86\x92no-cache, private\nConnection \xe2\x86\x92keep-alive\nContent-Type \xe2\x86\x92application/json\nRun Code Online (Sandbox Code Playgroud)\n\n这是 Postman 上通过请求设置的内容。我也从浏览器发送这些标头。关于可能导致该问题的原因有什么想法吗?这真让我抓狂。
\n\n public function refreshToken(Request $request) \n{ \n if (!is_null($request)) {\n $refreshToken = $request->cookie(self::REFRESH_TOKEN);\n\n $http = new Guzzle();\n $response = $http->request(\'POST\',\'http://192.168.10.10/oauth/token\', [\n \'form_params\' => [\n \'grant_type\' => \'refresh_token\',\n \'refresh_token\' => $refreshToken,\n \'client_id\' => env("PASSWORD_GRANT_CLIENT_ID"),\n \'client_secret\' => env("PASSWORD_GRANT_SECRET"),\n \'scope\' => \'\',\n ]\n ]);\n $data = json_decode($response->getBody());\n $this->cookie->queue(\n self::REFRESH_TOKEN,\n $data->refresh_token,\n 864000, // 10 days\n null,\n null,\n false,\n true // HttpOnly\n );\n\n return response()->json([\n \'payload\' => [\n \'access_token\' => $data->access_token,\n \'expires_in\' => $data->expires_in\n ]\n ]);\n\n } else {\n return response()->json("Could not refresh token", 401);\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n\n\n这是邮递员请求的内容。
\n\n\n\n这就是我困惑的地方。
\n\n没有参数通过此 POST 请求传递。\n我的 api 上启用了 CORS,未收到飞行前错误。\n两个请求的标头相同。\n唯一的区别是使用了 Postman 和使用了 Axios。\n什么都没有更改,但通过 Postman 或浏览器发出请求的位置除外。
\n| 归档时间: |
|
| 查看次数: |
38838 次 |
| 最近记录: |