我正在使用 connect id处理rstudio登录。检索 code 后 API 返回错误:{"error":"invalid_grant","error_description":"grant request is invalid"} 我不知道为什么:
$ch=curl_init();
$header = array('Authorization: Basic '.base64_encode($client_id.':'.$secret), 'Content-Type: application/x-www-form-urlencoded');
$post = array('grant_type' => 'authorization_code',
'code' => $code,
'redirect_uri' => 'MY_URL');
$url = "https://eif-til.onelogin.com/oidc/token";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
$result = curl_exec($ch);
输入的所有变量似乎都正常,收到的授权码似乎正常并按原样传递。在 Onelogin 方面,一切似乎都按应有的方式配置。我怀疑是 PHP Curl 代码,但我不知道缺少什么/错了什么
最佳答案
您的 Content-Type
header 不正确:
$header = array('Authorization: Basic '.base64_encode($client_id.':'.$secret), 'Content-Type=application/x-www-form-urlencoded');
应阅读:
$header = array('Authorization: Basic '.base64_encode($client_id.':'.$secret), 'Content-Type: application/x-www-form-urlencoded');
即在名称和值之间使用“冒号”而不是“=”。
关于php - Onelogin 和 ID token : grant request is invalid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51077829/