我在PHP网站设置基本身份验证,发现此页面上显示的设置PHP手册.标题中的"领域"是什么意思?
header('WWW-Authenticate: Basic realm="My Realm"');
是请求的页面页面吗?
摘要和基本身份验证有什么区别?
authentication https http basic-authentication digest-authentication
我正在尝试发送需要HTTP摘要身份验证的请求.
在jQuery中可以使用Digest吗?
如果是这样,这是否接近正确的方法呢?它目前无法正常工作.
<script type="text/javascript">
    $.ajax({
        url: url,
        type: 'GET',
        dataType: 'json',
        success: function() { alert('hello!'); },
        error: function() { alert('error')},
        beforeSend: setHeader
    });
    function setHeader(xhr){
        xhr.setRequestHeader("Authorization", "Digest username:password");
        xhr.setRequestHeader("Accept", "application/json");
    }
</script>
这可能是一个愚蠢的问题,但我可以安全地使用基本的HTTP身份验证,或者即使服务器已经在SSL上,我仍然可以从摘要身份验证中受益吗?
authentication ssl https basic-authentication digest-authentication
我刚刚使用Mechanize模块,现在尝试使用Requests模块.
(当需要HTTPS和代理身份验证时,Python机制不起作用)
当我访问互联网时,我必须通过代理服务器.
代理服务器需要身份验证.我写了以下代码.
import requests
from requests.auth import HTTPProxyAuth
proxies = {"http":"192.168.20.130:8080"}
auth = HTTPProxyAuth("username", "password")
r = requests.get("http://www.google.co.jp/", proxies=proxies, auth=auth)
当代理服务器需要基本身份验证时,上述代码很有效.
现在我想知道当代理服务器需要摘要式身份验证时我必须做什么.
HTTPProxyAuth似乎在摘要式身份验证中无效(r.status_code返回407).
基本上我需要做的是执行摘要式身份验证.我尝试的第一件事是这里提供的官方示例.但是当我尝试执行它时(通过一些小的更改,Post而不是Get方法)我得到了一个
org.apache.http.auth.MalformedChallengeException: missing nonce in challange
at org.apache.http.impl.auth.DigestScheme.processChallenge(DigestScheme.java:132)
当这次失败时我尝试使用:
DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(new AuthScope(null, -1, null), new UsernamePasswordCredentials("<username>", "<password>"));
HttpPost post = new HttpPost(URI.create("http://<someaddress>"));
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("domain", "<username>"));
post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
DigestScheme digestAuth = new DigestScheme();
digestAuth.overrideParamter("algorithm", "MD5");
digestAuth.overrideParamter("realm", "http://<someaddress>");
digestAuth.overrideParamter("nonce", Long.toString(new Random().nextLong(), 36));
digestAuth.overrideParamter("qop", "auth");
digestAuth.overrideParamter("nc", "0");
digestAuth.overrideParamter("cnonce", DigestScheme.createCnonce());
Header auth = digestAuth.authenticate(new
      UsernamePasswordCredentials("<username>", "<password>"), post);
System.out.println(auth.getName());
System.out.println(auth.getValue());
post.setHeader(auth);
HttpResponse ret = client.execute(post);
ByteArrayOutputStream v2 = new ByteArrayOutputStream();
ret.getEntity().writeTo(v2);
System.out.println("----------------------------------------");
System.out.println(v2.toString()); …java android digest-authentication apache-commons-httpclient
我试着在php上做这个请求,从我的Bitbucket私有存储库下载最后一个源:
curl --digest --user user:pass https://bitbucket.org/user/repo/get/tip.zip -o test.zip
在命令行它确定,文件下载完美,但在PHP不工作,这我的PHP代码:
$out = fopen('test.zip', 'w+');
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_USERPWD, 'user:pass');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FILE, $out);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, 'https://bitbucket.org/user/repo/get/tip.zip');
curl_exec($ch);
这是响应,登录无效,服务器重定向到登录页面:
Error CURL: '' 
Error number: 0
Array
(
    [url] => https://bitbucket.org/account/signin/?next=/user/repo/get/tip.tar.gz
    [content_type] => text/html; charset=utf-8
    [http_code] => 200
    [header_size] => 1099
    [request_size] => 194
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => …在Authorization intro页面上,Apache告诉我们:
Apache支持另一种身份验证方法:AuthType Digest.此方法由mod_auth_digest实现,并且更加安全.
在mod_auth_digest页面上,Apache告诉我们:
此模块实现HTTP摘要式身份验证(RFC2617),并提供mod_auth_basic的替代方法,其中密码不以明文形式传输.但是,与基本身份验证相比,这不会带来显着的安全优势.另一方面,与基本身份验证相比,使用摘要式身份验证的服务器上的密码存储安全性更低.
有人可以为我澄清这些看似矛盾的陈述吗?我知道处理密码的两种方式都容易受到重放攻击(除非你也使用SSL),但这似乎是一个单独的问题.
apache security authentication basic-authentication digest-authentication
如何使用WebClient.DownloadFile摘要式身份验证和查询字符串?
当我尝试使用它时,我得到401响应.
这是Apache错误日志:
[Tue Jun 24 17:31:49 2014] [error] [client x.x.x.x] Digest: uri mismatch - </file-1.php> does not match request-uri </file-1.php?since=1403587422>
以下是我尝试下载文件的方法:
Uri uri = new Uri("http://example.com/file-1.php?since=1403587422");
WebClient webClient = new WebClient();
CredentialCache credentialCache = new CredentialCache();
credentialCache.Add(
  new Uri(uri.GetLeftPart(UriPartial.Authority)),
  "Digest",
  new NetworkCredential("username", "password")
);
webClient.Credentials = credentialCache;
webClient.DownloadFile(uri, file.OutputFile);