Onelogin和ID令牌:授予请求无效

时间:2018-06-28 08:10:13

标签: php api curl token onelogin

我正在使用connect id处理rstudio登录。收起code后 API返回错误:{“ error”:“ invalid_grant”,“ error_description”:“授予请求无效”}},我不知道为什么:

$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代码的,但是我不知道缺少什么/错了

2 个答案:

答案 0 :(得分:0)

您的Content-Type标头不正确:

$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');

即在名称和值之间使用“冒号”而不是“ =“。

答案 1 :(得分:0)

如果您使用的是PKCE,并且错过了code_verifier参数或参数不正确(包括在上一步中错误生成code_challenge的情况),您还会收到“授予请求无效”响应。