我通过命令行中的curl(但在php中需要)得到了我想要的(令牌),方法是:
curl -d "client_id=theClient" -d "grant_type=password" "https://auth.theClient.de/auth/openid-co/token"
然后我尝试用php实现它:
<?php
$requestURL = 'https://auth.theClient.de/auth/openid-co/token';
$postData = "grant_type=password&client_id=theClient&scope=openid";
$headers[0] = 'Content-Type: application/x-www-form-urlencoded';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $requestURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$response = curl_exec($ch);
$responseArray = json_decode($response, TRUE);
var_export($responseArray);
应该给我令牌,但我收到了错误的请求和响应:
array (
'error_description' => 'X509 client certificate is missing.',
'error' => 'invalid_request',
)
我把证书导入Chrome Webbrowser(Stand & Gt;Advanced)。
我假设在apache webserver或php脚本(p12密钥库)中的配置中缺少证书。