【发布时间】:2017-10-31 07:23:11
【问题描述】:
我正在使用以下代码访问 OpenId 系统并请求不记名令牌。
if (isset($_GET['code'])) {
// try to get an access token
$code = $_GET['code'];
$url = 'https://3rdpartydomain.com/connect/token';
$params = array(
"code" => $code,
"client_id" => CLIENTID,
"client_secret" => CLIENTSECRET,
"redirect_uri" => 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"],
"grant_type" => "authorization_code"
);
$ch = curl_init();
curl_setopt($ch, constant("CURLOPT_" . 'URL'), $url);
curl_setopt($ch, constant("CURLOPT_" . 'POST'), true);
curl_setopt($ch, constant("CURLOPT_" . 'POSTFIELDS'), $params);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] === 200) {
header('Content-Type: ' . $info['content_type']);
return $output;
} else {
return 'An error happened';
}
} else {
$url = "https://3rdpartydomain.com/connect/token";
$params = array(
"response_type" => "code",
"client_id" => CLIENTID,
"redirect_uri" => 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"],
"scope" => "openid"
);
$request_to = $url . '?' . http_build_query($params);
header("Location: " . $request_to);
}
但是,我收到以下消息:
{"Message":"The requested resource does not support http method 'GET'."}
有人可以帮忙确定我的代码的正确性吗?
谢谢!
【问题讨论】: