简体   繁体   English

在 Apache (API) 的 url 中传递凭据

[英]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.

相关问题 使用URL重写将URL作为参数传递(Apache) - Passing an URL as a paramter using URL rewriting (apache) Zend Framework:Apache解码编码的URL而不是传递编码的URL? - Zend Framework: Apache decoding encoded URL instead of passing encoded URL? Apache vHost和API“漂亮的网址”获得404 - Apache vHost and API “pretty url” getting 404 在htaccess网址重写中传递任何参数(在Apache中为mod_rewrite) - Passing any parameters in htaccess url rewriting (mod_rewrite in Apache) .htaccess网址重写未传递参数-可能在某处设置了apache设置来防止这种情况吗? - .htaccess url rewrite not passing parameter - could there be apache settings somewhere that is preventing this? 替换URL结构并传递内容MOD_REWRITE和Apache - Replacing URL structure and passing through content MOD_REWRITE & Apache 如何将凭据传递到位于.htaccess保护的Apache Web服务器上的PHP api端点 - How to pass credentials to PHP api endpoint located on .htaccess protected apache web server 用于在此URL中获取Laravel API的Apache配置:www.example.com/api - Apache configuration to get Laravel API in this url : www.example.com/api 我的API中的Apache URL重写,如http://www.example.com/api/list/office?key=abc - Apache URL Rewrite in my API like http://www.example.com/api/list/office?key=abc 如何将Windows凭据添加到Apache骆驼路线? - How to add windows credentials to an apache camel route?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM