authentication - Laravel HTTP 客户端检索 REST API 访问令牌
问题描述
尝试从 MS Azure 检索访问令牌
像这样的东西:
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Http;
use Illuminate\Http\Client\Response;
class HttpController extends Controller
{
public function index()
{
$url = "https://login.microsoftonline.com/[tenantId]/oauth2/token";
$response = HTTP::post($url,
[
'grant_type' => 'client_credentials',
'client_Id' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
'client_secret' => '***************************',
'resource' => 'https://management.azure.com',
]);
dd($response);
}
}
得到以下错误:
“error”:“invalid_request”,“error_description”:“AADSTS900144:请求正文必须包含以下参数:'grant_type'
解决方案
$response = HTTP::asForm()->post($url,
[
'grant_type' => 'client_credentials',
'client_Id' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
'client_secret' => '***************************',
'resource' => 'https://management.azure.com',
]
);
推荐阅读
- c# - 消息验证引发“未找到消息”异常
- swift - 等待应用程序窗口打开后再继续
- reactjs - React:处于防止重新渲染状态的类实例
- react-native - 缩小时iOS上的React-native-maps崩溃
- c# - 无法在 Unity 中使用 HTTP 客户端连接到我的 API
- node.js - Node Js:Redis作业在完成其任务后未完成
- c++ - C++模板参数指定第二个
- javascript - 构造html列匹配类
- api - 需要在 SharedPreferences 中保存我的登录 api json 响应
- azure - 有没有办法从天蓝色搜索索引中删除旧数据