我正在尝试使用 POST 和嵌套参数进行 Http Basic 身份验证。虽然外部参数工作正常(class.name - ActionController::Parameters),但嵌套参数是字符串(class.name - String)这是我的代码 ->
require 'net/http'
uri = URI('http://example.com/bulb/')
req = Net::HTTP::Post.new(uri)
req.basic_auth 'mytest@somesite.com', 'mypassword'
req.set_form_data('first_params' => 'a', 'seconnd_params'=>'b', 'netsed_params'=>{'first_netsed'=>'c', 'second_nested'=>'d'}, 'commit'=>'Create Bulb', 'action'=>'create', 'controller'=>'bulb')
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
http.request(req)
end
case res
when Net::HTTPSuccess, Net::HTTPRedirection
# OK
else
#failed
end
Run Code Online (Sandbox Code Playgroud)
我可以使用什么其他库来使嵌套参数工作而无需手动转换它们。我发现这set_form_data不适用于嵌套哈希
我已经浏览了许多与使用基本身份验证触发 GET 请求相关的类似帖子(例如:Python、带有基本身份验证的 HTTPS GET),但仍然无法找出问题。我不断收到错误requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url
使用相同的凭据,标头在邮递员中尝试了相同的操作,它按预期工作。已验证 api_key、password 的 base64encoded 值与 postman 中使用的值完全相同,因此我不认为其编码或资源访问权限问题。
python -V
Python 3.6.4 :: Anaconda, Inc.
Run Code Online (Sandbox Code Playgroud)
方法一
api_key = 'some_api_key'
password = 'some_password'
headers = {'accept': 'application/json'}
url = 'https://test.access.com/this/url'
api_key_password = "%s:%s" % (api_key, password)
b64_encoded = b64encode(bytes(api_key_password, 'utf-8')).decode("ascii")
headers['authorization'] = 'Basic %s' % b64_encoded
response = requests.get(url,
headers=headers)
if (response.ok):
json_data = json.loads(response.content)
print (json_data)
else:
print (response)
response.raise_for_status()
Run Code Online (Sandbox Code Playgroud)
方法2
api_key = 'some_api_key'
password = 'some_password' …Run Code Online (Sandbox Code Playgroud) 我完全是 Django 的初学者(来自 Node/Express 背景)。我需要调用使用基本授权的 API。
为了发出请求,我正在使用请求模块,但我不知道在哪里传递身份验证标头。在 Axios 中,我通常设置默认标头,如下所示:
import axios from 'axios'
const token = `Basic ${Buffer.from(`${process.env.API_USERNAME}:${process.env.API_PASSWORD}`).toString('base64')}`;
axios.defaults.baseURL = process.env.API_URL;
axios.defaults.headers.common['Authorization'] = token;
Run Code Online (Sandbox Code Playgroud)
我在 Django 中的服务:
from base64 import b64encode
import requests
import environ
environ.Env.read_env()
endpoint = 'some url'
credentials = f"{env('API_USERNAME')}:{env('API_PASSWORD')}"
encodedCredentials = str(b64encode(credentials.encode("utf-8")), "utf-8")
auth = f'"Authorization": "Basic {encodedCredentials}"'
def get_api_data():
return requests.get(endpoint).json()
Run Code Online (Sandbox Code Playgroud)
我应该如何传递标题?
我想使用云调度程序来调度 HTTP 请求。我部署在 k8s 上的服务正在使用基本身份验证。如何给作业添加这样的授权呢?是否需要在服务帐户内指定此授权?我是的-那怎么办?我是否应该使用 OIDC 令牌,因为 OAuth 似乎不合适?非常感谢您的任何答复。无论如何祝你有美好的一天:)
basic-authentication google-cloud-platform google-cloud-scheduler
在我的Apache 2配置中,我有一个VirtualHost看起来像这样的东西:
<VirtualHost *:80>
ServerName sub.domain.com
# username:password sent on to endpoint
RequestHeader set Authorization "Basic dXNlcm5hbWU6cGFzc3dvcmQ=="
ProxyPass /xyz http://192.168.1.253:8080/endpoint
ProxyPassReverse /xyz http://192.168.1.253:8080/endpoint
<Location /xyz>
# This needs to let users through under the following circumstances
# * They are in 192.168.1.0/24
# * They have a valid user in a htpasswd file
# So what goes here?
</Location>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
我正在使用虚拟主机作为网络上另一台服务器(我称之为端点)的反向代理.
我试图找出一种配置,允许网络内部的用户sub.domain.com自动为端点提供服务.但是,应提示网络外的用户提供凭据
端点需要一个我使用RequestHeader(我想要的)隐藏的密码.外部用户的密码应该是不同的,需要是BasicAuth,从htpasswd文件中获取用户列表.
免责声明:我不是Notes管理员,我只是编写了应用程序:),并尝试帮助我们的客户使用它.
我们提供一个简单的数据库,其中包含一个代理,用于接受和处理来自Internet的HTTP POST消
将要安装此数据库的Domino服务器配置为用于Web访问的单点登录身份验证.
有没有办法只设置我们的数据库使用不同类型的身份验证 - 即基本身份验证,所以我们可以像这样命令POST消息给代理:
HTTP://用户名:password@my.domino.server/mydb.nsf/myagent
我还想到了另一种方法 - 删除任何形式的auth,并在POSTed数据中传递凭据.然后,代理将注意处理或不处理数据,基于信用是否正常.但这很可能需要某种形式的"冒充" - 即以某种方式将匿名用户映射到具有执行代理权限的用户.所以,我对这个问题的有效答案可能是一个建议如何设置它.
此外 - 我们正在研究Web服务方法(在Domino 7.0+中可用),但它需要对双方进行更改 - 发件人(我们的发布者服务)和接收代理.并且很可能会回到关于如何验证发件人的原始问题.
任何有关这方面的建议(甚至改变方法)都将受到高度赞赏.
干杯
我正在用django/tastpie构建一个RESTful api.在我的开发(本地)环境中运行时,一切都很好,并且可以正确验证.
Marks-MacBook-Pro:~ mshust$ curl http://127.0.0.1:8000/api/v1/speedscreen/ -H 'Authorization: Basic bXNodXN0MToyMjY3' -v
* About to connect() to 127.0.0.1 port 8000 (#0)
* Trying 127.0.0.1...
* connected
* Connected to 127.0.0.1 (127.0.0.1) port 8000 (#0)
> GET /api/v1/speedscreen/ HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: 127.0.0.1:8000
> Accept: */*
> Authorization: Basic bXNodXN0MToyMjY3
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Date: Thu, 09 Aug 2012 01:36:05 GMT
< Server: WSGIServer/0.1 Python/2.7.2
< Content-Type: …Run Code Online (Sandbox Code Playgroud) 我需要对以下URL执行请求:
HTTP:// [USERNAME]:[PASSWORD] @ [SERVER_IP]:[PORT] /一些/路径/到/一些/文件
但最终生成的URL被视为INVALID,因为它包含两次":"字符.有什么解决方案吗?
这就是我试过的:
$process = curl_init('http://[SERVER_IP]:[PORT]/OpenKM/webdav/okm:personal/somefile.mp4');
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_USERPWD, "[USERNAME]:[PASSWORD]");
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($process); // $return is FALSE
var_dump(curl_error($process));die(); // Here we see string(23) "Empty reply from server"
Run Code Online (Sandbox Code Playgroud) 我通过传递用户名和密码进行基本身份验证,然后使用BasicNameValuePair发送post params来获取服务的响应.
我的方法:
public StringBuilder callServiceHttpPost(String userName, String password, String type)
{
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(WEBSERVICE + type);
HttpResponse response = null;
StringBuilder total = new StringBuilder();
try {
URL url = new URL(WEBSERVICE + type);
/*String base64EncodedCredentials = Base64.encodeToString((userName
+ ":" + password).getBytes(), Base64.URL_SAFE
| Base64.NO_WRAP);*/
String base64EncodedCredentials = "Basic " + Base64.encodeToString(
(userName + ":" + password).getBytes(),
Base64.NO_WRAP);
httppost.setHeader("Authorization", base64EncodedCredentials);
// Add …Run Code Online (Sandbox Code Playgroud) 我正在使用WCF针对客户的SOAP服务编写客户端.
我们已经进行了多次复飞,试图让身份验证正常运行.我最终使用了Custom Binding,因为Web上的一些随机人员说BasicHttpBinding不支持必要的安全选项,而且WsHttpBinding不支持SOAP 1.1,这就是他们正在使用的.
那么,我有什么:
var message = this.constructMessagecollection);
if (message != null)
{
var ea = new EndpointAddress(this.webServiceUrl);
var binding = new CustomBinding();
binding.Elements.Add(new TextMessageEncodingBindingElement(
MessageVersion.Soap11, Encoding.UTF8));
binding.Elements.Add(new HttpsTransportBindingElement { AuthenticationScheme = System.Net.AuthenticationSchemes.Basic });
using (var client = new CustomersWebserviceClient(binding, ea))
{
if (!String.IsNullOrWhiteSpace(this.webServiceUsername) && !String.IsNullOrWhiteSpace(this.webServicePassword))
{
var credentials = client.ClientCredentials.UserName;
credentials.UserName = this.webServiceUsername;
credentials.Password = this.webServicePassword;
}
var result = client.ReceiveMessage(message);
log.writeLine(String.Format("Call to client.ReceiveMessage() returned {0}", result));
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
现在,我被问到是否可以将我的客户端配置为执行抢占式身份验证.我做了一些网页浏览,但没有找到太多.而且我不知道如何将我发现的很少的东西整合到我当前的代码中.