使用qop=auth-int的PHP客户端摘要式身份验证


PHP client side Digest authentication with qop=auth-int

有人知道任何用于连接使用qop=auth-int的摘要式身份验证方法的远程服务器的PHP库吗?或者,如果没有,现在我应该为结果构建A2吗?RFC 2617中说我需要使用实体,但这是什么?我只是发送一个GET请求,它根本没有任何正文。提前谢谢。

我也在寻找你的问题的答案,除了GET之外的其他请求。Perheps你可以使用类似的东西:

$entityBody = file_get_contents('php://input');

我还没有测试它是否有效,但看看这个问题的答案,我会觉得它应该有效。

请注意,此流只能读取一次[1],因此如果您在其他地方再次需要它,则应重用$entityBody变量。

根据我对类似问题的回答:

我最近用cURL在PHP中实现了客户端摘要式身份验证。这是完整的代码:

<?php
error_reporting(E_ALL); 
ini_set( 'display_errors','1');
$url = "https://api.example.com/ws.asmx/do";
$username = "username";
$password = "pwd";
$post_data = array(
        'fieldname1' => 'value1',
        'fieldname2' => 'value2'
  );
$options = array(
        CURLOPT_URL            => $url,
        CURLOPT_HEADER         => true,    
        CURLOPT_VERBOSE        => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_SSL_VERIFYPEER => false,    // for https
        CURLOPT_USERPWD        => $username . ":" . $password,
        CURLOPT_HTTPAUTH       => CURLAUTH_DIGEST,
        CURLOPT_POST           => true,
        CURLOPT_POSTFIELDS     => http_build_query($post_data) 
);
$ch = curl_init();
curl_setopt_array( $ch, $options );
try {
  $raw_response  = curl_exec( $ch );
  // validate CURL status
  if(curl_errno($ch))
      throw new Exception(curl_error($ch), 500);
  // validate HTTP status code (user/password credential issues)
  $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  if ($status_code != 200)
      throw new Exception("Response with Status Code [" . $status_code . "].", 500);
} catch(Exception $ex) {
    if ($ch != null) curl_close($ch);
    throw new Exception($ex);
}
if ($ch != null) curl_close($ch);
echo "raw response: " . $raw_response; 
?>

如果您正在执行GET请求,则不需要auth-int。如果您的服务需要它,您可以假设一个空的实体主体(因此您可以只为A2哈希的这一部分执行md5("))。