标签: basic-authentication

HTTP基本身份验证似乎不能在python中使用urllib2

我正在尝试使用urllib2下载受基本身份验证保护的页面.我正在使用python 2.7,但我也在另一台使用python 2.5的计算机上尝试过它,并遇到了完全相同的行为.我尽可能地遵循本指南中给出的示例,是我生成的代码:

import urllib2

passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, "http://authenticationsite.com/', "protected", "password")
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)

f = opener.open("http://authenticationsite.com/content.html")
print f.read()
f.close()
Run Code Online (Sandbox Code Playgroud)

不幸的是服务器不是我的,所以我不能分享细节; 我把它们从上面和下面换了出来.当我运行它时,我得到以下Traceback:

  File
"/usr/lib/python2.7/urllib2.py", line
397, in open
response = meth(req, response)   File "/usr/lib/python2.7/urllib2.py",
line 510, in http_response
'http', request, response, code, msg, hdrs)   File
"/usr/lib/python2.7/urllib2.py", line
435, in error
return self._call_chain(*args)   File "/usr/lib/python2.7/urllib2.py",
line 369, in _call_chain
result = func(*args)   File "/usr/lib/python2.7/urllib2.py", line
518, in http_error_default
raise HTTPError(req.get_full_url(), code,
msg, hdrs, …
Run Code Online (Sandbox Code Playgroud)

python urllib2 basic-authentication

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

如何使用基本身份验证配置spring security以对数据库进行身份验证?

我用Java编写了13周的时间,正在开发一个RESTful Web服务.后端已完成,现在我正在创建一个UI.其中一个要求是用户使用http basic登录.我已将此配置为当用户导航到页面时弹出对话框出现的位置,您可以输入我所拥有的一个硬编码用户并将其登录.但我真正需要它做的是验证用户是否在一个数据库.我已经广泛搜索,试图找到一种方法来配置它来验证数据库,但无济于事.这是我的假用户的spring-security.xml文件.

<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security-3.1.xsd">

    <!-- <http auto-config="true"> <intercept-url pattern="/welcome*" access="ROLE_USER" 
        /> <form-login login-page="/login" default-target-url="/welcome" authentication-failure-url="/loginfailed" 
        /> <logout logout-success-url="/logout" /> </http> -->

    <http>
        <intercept-url pattern="/*" access="ROLE_USER" />
        <http-basic />
    </http>

    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="tmain" password="123456" authorities="ROLE_USER" />
            </user-service>
        </authentication-provider>
    </authentication-manager>

</beans:beans>
Run Code Online (Sandbox Code Playgroud)

这里(我相信)只有我的web.xml文件中的设置相关信息.

<filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
Run Code Online (Sandbox Code Playgroud)

任何人都可以给我一些关于配置spring security以对数据库进行身份验证的方向,而不是我的虚拟用户吗?我在数据库中有一个User实体,其中包含firstname,lastname,email,password,activeStatus和timezone.电子邮件是用户的用户名.任何和所有的帮助将不胜感激.

java spring-security basic-authentication

9
推荐指数
1
解决办法
4431
查看次数

android中的BasicAuthentication for webview无法正常工作

嗨,我想从我的android webview 打开这个网址http://3864.cloud-matic.net/,我尝试了很多方法,但应用程序甚至没有打开mainActivity.我试过的是下面的内容.

 public void onCreate(Bundle state) {
    super.onCreate(state);
    setContentView(R.layout.main);
    WebView webView = (WebView) findViewById(R.id.webView1);
    webView.setHttpAuthUsernamePassword("cloud-matic.net/",     "realm", username, password);
    webView.loadUrl("http://3864.cloud-matic.net/");
}
Run Code Online (Sandbox Code Playgroud)

请告诉我哪里错了.阿里

java android basic-authentication webview

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

在angularjs中为此HTTP GET添加HTTP基本身份验证

我有一个现有的angularjs代码,它可以生成HTTP GET.下面提取的是控制器内部的一些相关代码.

    .controller('imptViewCtrl', ['$scope', '$http', 
        function ($scope, $http, ) {
                    var url = $configuration.webroot + '/impt/list?list=testlist';
                    $http.get(url).then(function (response) {
                               tableData = response.data;
                               });
        }]);
Run Code Online (Sandbox Code Playgroud)

我想将HTTP基本身份验证添加到HTTP GET.用户名是foo,密码是bar.如何才能做到这一点?

javascript http http-get basic-authentication angularjs

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

嵌入式Jetty 7服务器的基本身份验证,没有web.xml文件

我有一个作为服务运行的Jetty 7的嵌入式实现,并且想要为servlet添加没有web.xml文件的基本身份验证.

我使用此处描述的步骤创建了我的凭据

我以为我可以创建服务器,使用基本身份验证创建安全处理程序并将HashLoginService附加到安全管理器.但我显然遗漏了几件事,因为我从来没有得到凭证的提示.

下面是代码.任何帮助将不胜感激.

    server = new Server(port);
    server.addConnector(getSslChannelConnector(securePort));
    server.setGracefulShutdown(1000);
    server.setStopAtShutdown(true);

    // create the context handler for the server
    ServletContextHandler sch = new ServletContextHandler(server, WEBAPP_CONTEXT);

    // attach the security handler to it that has basic authentication
    sch.setSecurityHandler(getSecurityHandler());

    // define the processing servlet.
    sch.addServlet(new ServletHolder(new ProcessingServlet()), "/process");

    .
    .
private SecurityHandler getSecurityHandler() {

    // add authentication
    Constraint constraint = new Constraint(Constraint.__BASIC_AUTH,"user");
    constraint.setAuthenticate(true);
    constraint.setRoles(new String[]{"user","admin"});

    // map the security constraint to the root path.
    ConstraintMapping cm = new ConstraintMapping(); …
Run Code Online (Sandbox Code Playgroud)

jetty basic-authentication

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

如何使ServiceStack身份验证工作?(使用iPhone客户端)

我们聘请了一位为我们编写iPhone应用程序的承包商,我开始用ServiceStack为它编写后端服务.

我一般都在努力获得授权:使用何种授权以及如何实施授权.
我对ServiceStack,HTTP和授权(我)了解不多.我读过这篇文章,但我可能还是做错了.

我将使用现有遗留数据库中的用户名和密码进行身份验证(但没有别的 - 没有注册新用户,没有不同的权限.只是进行身份验证).
所以我需要编写自己的提供者.

我已经设法在本教程CredentialsAuthProvider的帮助下实现了一个工作. 它在我在浏览器中测试时有效:

  • 拨打我的服务并获得401
  • 发布到 auth/credentials
  • 再次呼叫我的服务并获得正确的结果

但是,我注意到当我在Fiddler中尝试时,相同的工作流程不起作用.

POST auth/credentials工作.我发布这个:

POST http://localhost:52690/auth/credentials?format=json HTTP/1.1
User-Agent: Fiddler
Host: localhost:52690
Content-Length: 74
Content-Type: application/json; charset=utf-8

{
  "UserName": "chspe",
  "Password": "xyz",
  "RememberMe": true
}
Run Code Online (Sandbox Code Playgroud)

......得到这个:

HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Fri, 14 Jun 2013 13:07:35 GMT
X-AspNet-Version: 4.0.30319
X-Powered-By: ServiceStack/3,949 Win32NT/.NET
Set-Cookie: ss-id=3YUUgfwIeJd7PedFK5Th; path=/; HttpOnly
Set-Cookie: ss-pid=zQJ5Z4Vq7AY+BpVwbttj; expires=Tue, 14-Jun-2033 13:07:35 GMT; path=/; HttpOnly
Set-Cookie: ss-opt=perm; expires=Tue, 14-Jun-2033 13:07:35 GMT; …
Run Code Online (Sandbox Code Playgroud)

c# authentication web-services basic-authentication servicestack

8
推荐指数
1
解决办法
5803
查看次数

如何将HTTP Basic Auth作为Sonatype Nexus URL的一部分用于工件下载?

我可以使用HTTP标头中的HTTP基本身份验证凭据从Sonatype Nexus下载该文件.

但是我无法通过将凭据作为URL的一部分来实现这一点 - 这样的事情:

http://admin:admin123@nexus.example.com/nexus/service/local/artifact/maven/content?g=com.test&a=project&v=1.0&r=test_repo_1_release
Run Code Online (Sandbox Code Playgroud)

有没有人知道为什么或如何在标题中不使用auth来实现相同的目的?

PS:这是一个测试环境 - 因此没有SSL.

nexus basic-authentication

8
推荐指数
1
解决办法
5387
查看次数

Yii 2 RESTful API使用HTTP Basic进行身份验证(Yii 2高级模板)

REST API无需身份验证方法即可运行.现在,我想通过移动应用程序对API请求进行HTTP基本身份验证来验证REST API.我试过yii2指南,但它对我不起作用.

基本上移动用户需要使用用户名和密码登录,如果用户名和密码正确,则用户需要登录,并且需要使用令牌进一步验证API请求.

当我调试findIdentityByAccessToken()函数时,$ token等于用户名.Postman扩展用于检查HTTP Basic请求.用户表中的access_token字段为空.我需要手动保存吗?如何将access_token作为响应返回?

这三种方法(HttpBasicAuth,HttpBearerAuth,QueryParamAuth)是否有任何原因,为什么?怎么样?

我的应用程序文件夹结构如下所示.

api
-config
-modules
--v1
---controllers
---models
-runtime
-tests
-web

backend
common
console
environments
frontend
Run Code Online (Sandbox Code Playgroud)

API \模块\ V1\Module.php

namespace api\modules\v1;
class Module extends \yii\base\Module
{
    public $controllerNamespace = 'api\modules\v1\controllers';

    public function init()
    {
        parent::init(); 
        \Yii::$app->user->enableSession = false;       
    }   
}
Run Code Online (Sandbox Code Playgroud)

API \模块\ V1 \控制器\ CountryController.php

namespace api\modules\v1\controllers;
use Yii;
use yii\rest\ActiveController;
use common\models\LoginForm;
use common\models\User;
use yii\filters\auth\CompositeAuth;
use yii\filters\auth\HttpBasicAuth;
use yii\filters\auth\HttpBearerAuth;
use yii\filters\auth\QueryParamAuth;

class CountryController extends ActiveController
{
    public $modelClass = 'api\modules\v1\models\Country';    

    public …
Run Code Online (Sandbox Code Playgroud)

api rest basic-authentication yii2 yii2-advanced-app

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

配置HTTPS基本认证apache2.conf .htaccess

我有WD MyBookLive 2TB,并做了以下事情:

  • 将我自己的.htaccess保存到/ var/www/mysebserver,它指向位于/ etc/apache2 /的我自己的.htpasswd.
  • 授予.htaccess 777权限
  • 我的所有网页都与.htaccess位于同一个文件夹中.

.htaccess文件是:

AuthType Basic 
AuthName "Restricted Content" 
AuthUserFile /etc/apache2/.htpasswd 
Require valid-user
Run Code Online (Sandbox Code Playgroud)

问题是没有启用基本身份验证,我仍然可以访问HTML文件而无需任何身份验证.

而且即使我在apache2.conf中设置了以下内容,似乎也忽略了.htaccess文件:

<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>
Run Code Online (Sandbox Code Playgroud)

404时会抛出404内部服务器错误 AllowOverride All

Apache版本:2.2.9

如何激活基本身份验证?

php apache .htaccess basic-authentication

8
推荐指数
1
解决办法
406
查看次数

两个不同 Laravel 应用程序之间的交叉身份验证

在此输入图像描述

背景

这两个应用程序是用 PHP Laravel 开发的 Web 应用程序。在应用程序中,应用程序1和应用程序2是两个不同的应用程序,由两个不同的团队管理。应用程序 1 用于修剪视频,而应用程序 2 用于展示其视频。

目前两个应用的登录方式都是邮箱密码登录。

算法:

  1. 在应用程序1(例如Facebook)中,用户可以登录系统并上传视频以及一些表单详细信息。
  2. 然后,应用程序 1 修剪并处理视频并保存在文件系统中。
  3. 处理完成后,应用程序 1 将POST结果发送给应用程序 2(例如 Instagram)。
  4. 在应用程序 2 中,视频会与相应的用户信息一起上传并向公众展示。

问题

  • APP 1 如何对 APP 2 中的用户进行身份验证。
  • 在提供安全身份验证的同时,最好的方法和最用户友好的方法是什么

我关心的是应用程序 2 的身份验证部分。由于用户登录方法不同,我们如何在将视频发送到应用程序 2 之前对应用程序 1 中的用户进行身份验证?

我在 Google 上找到的一些作品

第一种方式:哈希(主密钥+ [INFO])

  1. 创建一个仅 App 1 和 App 2 知道的主密钥。然后使用一些额外信息(例如 time())对主密钥进行哈希处理。然后应用程序 2 可以使用自己的主密钥验证哈希信息,如果结果相似,则用户可以通过身份验证过程并直接在应用程序 2 上发布视频。

第二种方式:OAUTH 令牌

  1. 用户必须登录应用程序 2 并生成 OAUTH 令牌。然后,用户需要在应用程序 1 上提交 OAUTH 令牌以允许视频发布。这种方法并不是真正的用户友好,因为这种方法在某种程度上是开发人员的方法。

不太确定用于此类身份验证的术语。请随时在评论部分告诉我。非常感谢。

php authentication basic-authentication laravel laravel-5

8
推荐指数
1
解决办法
822
查看次数