将 jQuery 的 ajax() 函数与 SSL 客户端证书一起使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14567776/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using jQuery's ajax() function with an SSL client certificate
提问by Golo Roden
I want to make a XHR call to a REST service using the ajax()
function of jQuery. Basically, this works fine, but the REST service is only accessible by https, and requires the client to authenticate using a client certificate.
我想使用ajax()
jQuery的功能对REST 服务进行 XHR 调用。基本上,这工作正常,但 REST 服务只能通过 https 访问,并且需要客户端使用客户端证书进行身份验证。
How do I send a client certificate using jQuery's ajax()
function?
如何使用 jQuery 的ajax()
函数发送客户端证书?
采纳答案by Simon
It's possible to make ssl ajax calls if the request source and target are in the same domain and using https: Securing AJAX & SSL. But you can't make an ssl authentication within your ajax call.
如果请求源和目标在同一域中并使用 https: Securing AJAX & SSL ,则可以进行 ssl ajax 调用。但是您不能在 ajax 调用中进行 ssl 身份验证。
回答by Bruno
Client-certificate authentication is (a) only performed upon request by the server and (b) done transparently by the browser, as far as the HTTP and JavaScript layers are concerned.
就 HTTP 和 JavaScript 层而言,客户端证书身份验证 (a) 仅在服务器请求时执行,并且 (b) 由浏览器透明地完成。
When the server requests a client certificate (which may entail a re-negotiation following an HTTP request), the browser should offer a pop-up to select a certificate (which is browser-dependent and not under any JavaScript or HTML control) or select one automatically depending on its settings.
当服务器请求客户端证书(这可能需要在 HTTP 请求后重新协商)时,浏览器应提供一个弹出窗口来选择证书(依赖于浏览器,不受任何 JavaScript 或 HTML 控制)或选择一个自动取决于其设置。
As such, it's not up to jQuery's ajax()
function to do anything about the client certificate.
因此,ajax()
对客户端证书做任何事情并不取决于 jQuery 的功能。
Off the top of my head, I'm not sure whether the browser will trigger the client-certificate selection pop-up if it only occurs at first during that AJAX call (this is likely to be browser dependent). However, if the client-certificate selection has already been made (or if the choice is automatic), the browser will use it for authentication, as it would for any other normal request.
在我的头顶上,我不确定浏览器是否会触发客户端证书选择弹出窗口,如果它仅在该 AJAX 调用期间发生(这可能取决于浏览器)。但是,如果已经进行了客户端证书选择(或者如果选择是自动的),则浏览器将使用它进行身份验证,就像任何其他正常请求一样。