laravel - 无法授权或获取令牌
问题描述
我无法让 laravel 应用程序访问另一个 laravel 应用程序(同一服务器)中的 api 端点。我可以让它在终端和邮递员中工作,但不能从 laravel 应用程序本身,既获得身份验证令牌,又在邮递员和终端中使用工作,但不能在 laravel 中使用。(杀了我,这是前几天的工作)
我尝试了许多 Guzzle 和 curl 配置,在 Win 10 上使用 WAMP。Laravel 框架版本 5.3.31,PHP 7.2.18
try {
$response = $http->request('POST',$this->base_oauth_url. 'oauth/token', [
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded',
],
'form_params' => [
'grant_type' => 'password',
'client_id' => self::API_CLIENT_ID,
'client_secret' => self::API_SECRET,
'username' => self::API_USERNAME,
'password' => self::API_PASSWORD,
'scope' => '*',
],
'debug'=>$this->debug,
'allow_redirects' => false,
'verify' => false,
]);
} catch (ClientException $e) {
throw new Exception("Guzzle Error: {$e->getMessage()}");
} catch (Exception $e) {
throw new Exception("Send Error: ({$e->getCode()}): {$e->getMessage()}");
}
$response = json_decode((string) $response->getBody()->getContents());
$data = array();
$data['access_token'] = $response->access_token;
$data['refresh_token'] = $response->refresh_token;
错误:Guzzle 错误:客户端错误:POST http://mytestdomain.com/oauth/token
导致401 Unauthorized
响应:{"error":"invalid_client","message":"Client authentication failed"}
解决方案
推荐阅读
- java - 打开前置摄像头
- javascript - 将路径数组转换为对象数组分组
- r - 如何在 R 中自定义效果图?
- javascript - 将国家代码电话前缀转换为 ISO 3166-1 alpha-2 格式
- python - 如何在不重新加载页面的情况下根据选择字段中的选定值在网页上显示图像
- android - Mapbox 在 Android O 上不显示地图
- testing - 将 TestCafe 与 mobx 一起使用
- office-js - 在 Outlook 和加载项窗格之间拖放
- ios - 如何正确获取一组 EKCalendars
- python - 使用 REST API 从 Python 脚本请求数据