[英]Passing credentials in url for Apache (API)
Problem问题
I would like to pass credentials in an url to access my Apache server.我想在 url 中传递凭据以访问我的 Apache 服务器。
My .htaccess is set up for basic auth.我的 .htaccess 设置为基本身份验证。
AuthType Basic
And displays an Auth window where I can enter the credentials.并显示一个身份验证窗口,我可以在其中输入凭据。 All fine BUT ...
一切都很好但是...
The problem is that the url is within a script and is used to access an API.问题是 url 位于脚本中,用于访问 API。
<script>
....
ocpu.seturl("//xx.xx.xx.xx/ocpu/library/base/R")
....
</script>
What I tried我试过的
I tried to pass credentials using:我尝试使用以下方法传递凭据:
ocpu.seturl("//user:password@xx.xx.xx.xx/ocpu/library/base/R")
Or something like或者类似的东西
ocpu.seturl("////xx.xx.xx.xx?username=user&pass=password/ocpu/library/base/R")
But it does not work.但它不起作用。 In addition (and as expected), if I enter the credentials in a web browser, eg
此外(正如预期的那样),如果我在网络浏览器中输入凭据,例如
http://xx.xx.xx.xx?username=user&pass=password
it does not work (meaning the Auth window appears).它不起作用(意味着出现身份验证窗口)。
Is it not possible ?不可能吗? Or do I have to encode the credentials ?
还是我必须对凭据进行编码?
Thanks谢谢
Maybe you're going about this the wrong way.也许你以错误的方式解决这个问题。 You should host the webpage on the same server as the ocpu page, and then the credentials that the user enters when loading the webpage, will automatically be used when calling the API.
您应该将网页托管在与 ocpu 页面相同的服务器上,然后用户在加载网页时输入的凭据将在调用 API 时自动使用。
Did you try including your web front-end inside the app, as in the example apps?您是否尝试在应用程序中包含您的 Web 前端,如示例应用程序中那样?
Have you tried to pass the Basic Auth credentials in the authentication header?您是否尝试在身份验证标头中传递基本身份验证凭据? In plain JavaScript this can be done for example as following:
在普通的 JavaScript 中,这可以例如如下完成:
var invocation = new XMLHttpRequest();
invocation.open("GET", url, true, username, password);
invocation.withCredentials = true;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.