标签: basic-authentication

集成测试Rails API与基本身份验证

我正在尝试使用基本身份验证进行测试签名.我尝试过几种方法.请参阅下面的代码,了解失败尝试和代码的列表.有什么明显的我做错了.谢谢

class ClientApiTest < ActionController::IntegrationTest
  fixtures :all

  test "adding an entry" do

    # No access to @request
    #@request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("someone@somemail.com:qwerty123")

    # Not sure why this didn't work
    #session["warden.user.user.key"] = [User, 1]

    # This didn't work either
    # url = URI.parse("http://localhost.co.uk/diary/people/1/entries.xml")
    # req = Net::HTTP::Post.new(url.path)
    # req.basic_auth 'someone@somemail.com', 'qwerty123'

    post "/diary/people/1/entries.xml", {:diary_entry => {
                                              :drink_product_id => 4,
                                              :drink_amount_id => 1,
                                              :quantity => 3
                                             },
                                        }
    puts response.body
    assert_response 200
  end
end
Run Code Online (Sandbox Code Playgroud)

ruby authentication api ruby-on-rails basic-authentication

3
推荐指数
1
解决办法
4509
查看次数

如何使用urllib2使用Python对站点进行身份验证?

在Stackoverflow和网络上阅读了很多内容后,我仍然在努力让事情发挥作用.

我的挑战:使用Python和urllib2访问我所属的网站的受限制部分.

从我读过的代码应该是这样的:

mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()

url = 'http://www.domain.com'

mgr.add_password(None, url, 'username', 'password')
handler = urllib2.HTTPBasicAuthHandler(mgr)
opener = urllib2.build_opener(handler)

urllib2.install_opener(opener)

try:
    response = urllib2.urlopen('http://www.domain.com/restrictedpage')
    page = response.read()
    print page.geturl()
except IOError, e:
    print e
Run Code Online (Sandbox Code Playgroud)

打印不打印"http://www.domain.com/restrictedpage",但显示"http://www.domain.com/login",因此我的凭据未存储/处理,我正在重定向.

我怎样才能让它发挥作用?我已经尝试了好几天,并且一直在追求同样的死胡同.我已经尝试了所有我找不到的例子.

我的主要问题是:使用Python和urllib2对网站进行身份验证需要什么?快速提问:我做错了什么?

python authentication urllib2 basic-authentication

3
推荐指数
1
解决办法
2万
查看次数

如何使用POCO使用HTTP基本身份验证创建HTTP Post?

我正在尝试使用POCO制作带有HTTP基本身份验证的HTTP帖子(明文用户名和密码).我找到了一个Get的例子,并尝试修改它,但作为一个新手,我想我已经把它毁了它的用处.有人知道怎么做吗?

是的,我已经看到了另一个问题:POCO C++ - NET SSL - 如何发布HTTPS请求,但我无法理解它是如何尝试实现用户名和密码部分的.我也不明白"x-www-form-urlencoded"的用法.邮政需要这个吗?我没有表格.只想用用户名和密码参数POST到服务器.

passwords post http basic-authentication poco-libraries

3
推荐指数
1
解决办法
1万
查看次数

Solr 4具有基本认证

我正在尝试使用solrj连接到solr.我的solr实例在jetty中运行,并受基本身份验证保护.我发现这些链接包含相关信息.

http://grokbase.com/t/lucene/solr-user/1288xjjbwx/http-basic-authentication-with-httpsolrserver

使用Apache HttpClient进行抢占式基本身份验证4 但是,我仍然遇到以下异常:

Caused by: org.apache.http.client.ClientProtocolException
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:822)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:352)
... 5 more
 Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity.
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:625)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
... 8 more
Run Code Online (Sandbox Code Playgroud)

我还附上了我正在使用的代码片段.

public static void main(String[] args) throws SolrServerException, IOException {

    HttpSolrServer server = new HttpSolrServer("http://localhost:8983/solr/");

    DefaultHttpClient m_client =(DefaultHttpClient)server.getHttpClient(); 
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(USERNAME, PASSWORD);

    m_client.addRequestInterceptor(new PreemptiveAuthInterceptor(),0);
    (((DefaultHttpClient)m_client).getCredentialsProvider()).setCredentials(new AuthScope("localhost",8983), credentials);

    SolrInputDocument document = new SolrInputDocument();
    document.addField("id",123213);
    server.add(document);
    server.commit();

}
Run Code Online (Sandbox Code Playgroud)

}

class PreemptiveAuthInterceptor …
Run Code Online (Sandbox Code Playgroud)

authentication solr jetty basic-authentication jetty-8

3
推荐指数
1
解决办法
7309
查看次数

使用RestTemplate进行基本身份验证 - 编译错误 - 构造函数HttpClient()不可见

试图将基本身份验证添加到restTemplate

我遇到的问题是我无法初始化:(在代码片段中都有导入)

HttpClient client = new HttpClient();
Run Code Online (Sandbox Code Playgroud)

此代码解决了编译错误(没有建议eclipse可以解决此问题)

1)问题是什么?

2)我输入了错误的课程吗?

我的代码片段:

import org.apache.http.client.HttpClient;
//OR (not together)
import sun.net.www.http.HttpClient;


HttpClient client = new HttpClient(); //this line dosent compile
UsernamePasswordCredentials credentials =
new UsernamePasswordCredentials("USERNAME","PASS");
client.getState().setCredentials(
  new AuthScope("www.example.com", 9090, AuthScope.ANY_REALM),
  credentials);
CommonsClientHttpRequestFactory commons =
     new CommonsClientHttpRequestFactory(client);

RestTemplate template = new RestTemplate(commons);
SomeObject result = template.getForObject(
     "http://www.example.com:9090/",SomeObject.class
 );
Run Code Online (Sandbox Code Playgroud)

运行此获取异常:

> failed due to an unhandled exception: java.lang.Error: Unresolved
> compilation problems:     The constructor HttpClient() is not visible
>   The method getState() is undefined for …
Run Code Online (Sandbox Code Playgroud)

java rest spring basic-authentication http-headers

3
推荐指数
1
解决办法
1万
查看次数

使用REST API进行基本身份验证的双因素身份验证?

我正在实现一个REST API,它同时包含移动应用程序和基于浏览器的客户端和用户.基于我在此处以及在security.stackexchange中提出的问题以及之前的问题,我得出的结论是,尽可能长时间保持"RESTful",SSL基本身份验证对于身份验证已足够.问题是我还想实现双因素身份验证.是否可以在401 Authorization标头响应中添加标头,例如username:password:token,或者在完全独立的请求标头中,但在与客户端的基本auth响应相同的有效负载中?由于我正在使用node.js + express/connect,因此我可以访问整个HTTP协议堆栈,但出于可伸缩性的考虑,希望保持尽可能安静.在浏览器方面,

rest basic-authentication node.js two-factor-authentication

3
推荐指数
1
解决办法
1934
查看次数

如何从Flask API返回401身份验证?

我已经在Flask中开发了一个API,该API使用HttpBasicAuth对用户进行身份验证。API在提琴手中绝对正常,当我们通过错误的凭据时返回401,但是当我在登录页面上使用相同的凭据时,浏览器会弹出额外的弹出窗口。我真的不想看到这个额外的弹出窗口,它要求提供凭据(返回时浏览器的默认行为

401

WWW-Authenticate: Basic realm="Authentication Required"

)。

当在本地部署时,它工作正常,但在远程服务器上托管时,则无法工作。

我们如何实现401,让浏览器不显示弹出窗口以询问凭据。

basic-authentication www-authenticate flask python-2.7

3
推荐指数
2
解决办法
5683
查看次数

HTTP基本身份验证的编码密码字段

我使用PHP cURL与Rest API进行通信。大多数功能是使用X-Ephemeral-Tokens执行的,但是不幸的是,它们不允许通过这些功能给予删除权限,因此我必须实现一个通过HTTP Basic Authentication进行删除的功能。

我遇到的麻烦是测试帐户的密码是一个随机字符串,包括多个特殊字符(其中一些使用双引号)。通过将username:password组合用单引号引起来,我使用了普通的cURL二进制文件来处理请求,'但是我不确定如何将其转换为PHP。相关代码段如下。

$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/json",
                                              "Content-Type: application/json"));
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $uname . ":" . $pass);
curl_setopt($curl, CURLOPT_URL, "https://cloud.ravellosystems.com/api/v1/applications/" . $appid);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
$result = curl_exec($curl);
Run Code Online (Sandbox Code Playgroud)

我已经尝试过使用引号和URL编码进行各种组合,但仍然得到一个响应代码,表明身份验证不正确。

这是基于API文档显示的使用普通cURL的示例HTTP请求(略有修改)

curl -v -X DELETE -H "Content-Type: application/json" -H "Accept: application/json" --user ravello@ravello.com:password https://cloud.ravellosystems.com/api/v1/applications/414244
Run Code Online (Sandbox Code Playgroud)

任何有关如何解决此问题的建议,我们将不胜感激。

php encoding curl http basic-authentication

3
推荐指数
1
解决办法
4441
查看次数

使用c#和基本身份验证来使用Web服务

我想使用以下代码使用Web服务:

WebService.GenRelClient client = new WebService.GenRelClient();
client.ClientCredentials.UserName.UserName = @"UserName";
client.ClientCredentials.UserName.Password = @"Password";
var response = client.returnString("test");
Run Code Online (Sandbox Code Playgroud)

我的配置看起来像这样:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="GenRelClientPortBinding">
        <security mode="TransportCredentialOnly">
          <transport clientCredentialType="Basic" />
        </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint
          address="http://ws.domain.com/GenRel/GenRel"
          binding="basicHttpBinding"
          bindingConfiguration="GenRelClientPortBinding"
          contract="WebService.GenRelClientPort"
          name="GenRelClientPort" />
    </client>
  </system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)

请求被发送到Web服务,并且响应被发送回有关于它需要基本身份验证的错误消息,因为请求是在没有凭据的情况下发送的,所以我不知道哪里出错.

谢谢您的帮助

c# wcf web-services basic-authentication

3
推荐指数
1
解决办法
2万
查看次数

使用Apache 2.4 mod_proxy和基本身份验证在Docker容器中运行Portainer

问:如何使用基本身份验证将Apache 2.4配置为Portainer的反向代理?

Portainer是用于管理Docker容器的UI.Portainer文档有一个示例nginx配置,但遗憾的是没有apache.

apache user-interface reverse-proxy basic-authentication docker

3
推荐指数
1
解决办法
2323
查看次数