标签: basic-authentication

django - 使用基本身份验证保护一些Web路径

我是django的新手,只是尝试了几个简单的实验来弄湿我的脚.我正在运行django 1.0,apache2 prefork和mod_wsgi.我正在尝试使用以下url结构构建一个站点

/
/members
/admin
Run Code Online (Sandbox Code Playgroud)

根基本上是一个公共区域.
应使用基本身份验证(可能由apache进行身份验证)保护成员路径,应
使用内置的django身份验证来保护管理路径.

按照文档中的示例,我基本上可以使用基本身份验证保护整个站点,但这不是我想要的.

除了虚拟主机配置:

WSGIScriptAlias / /django/rc/apache/django.wsgi
<Directory /django/rc/apache>
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/django/_HTPASSWD/.htpasswd"
Require valid-user

# Order allow,deny
# Allow from all
</Directory>
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我指出正确的方向(或告诉我= P)如何使这成为可能?

谢谢


编辑:玩了一下我发现我可以做的事情:

WSGIScriptAlias / /django/rc/apache/django.wsgi
<Directory /django/rc/apache>
Order allow,deny
Allow from all
</Directory>

WSGIScriptAlias /members /django/rc/apache_httpauth/django.wsgi
<Directory /django/rc/apache_httpauth>
AuthType Basic
AuthName "Authentication Required"
AuthUserFile "/django/_HTPASSWD/.htpasswd"
Require valid-user

</Directory>
Run Code Online (Sandbox Code Playgroud)

django.wsgi文件基本上是复制到另一个目录的同一文件,因此WSGIScriptAlias是不同的.这是hack-ish,但它有效..

有没有更好的方法来做我想做的事情?
这样做有什么缺点吗?

谢谢

django mod-wsgi basic-authentication django-admin

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

apache:重写前的基本身份验证

我在前端有一个apache,通过重写规则重定向请求.我必须在重定向请求之前进行基本身份验证,所以我把它放在配置文件中:

<VirtualHost *:443>
    ServerAdmin xxxxxx
    DocumentRoot /var/www/html/
    ServerName xxxxxxx
    RewriteEngine on
    ErrorLog logs/error.log
    CustomLog logs/access_log common

    <Directory /var/www/html/>
        AuthType Basic
        AuthName "Restricted Files"
        AuthUserFile /etc/httpd/conf/tag.pwd
        Require valid-user
        RewriteRule ^/(.*) http://xxxxxx:xxx/$1   [P,L]
    </Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

但是不起作用.

有什么建议?

apache mod-rewrite basic-authentication

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

Heroku上的Rack :: Static应用程序的HTTP基本身份验证

我有一个在Heroku上托管的简单Rack应用程序.config.ru:

use Rack::Static, 
  :urls => ["/stylesheets", "/images", "/javascripts"],
  :root => "public"

run lambda { |env|
  [
    200, 
    {
      'Content-Type'  => 'text/html', 
      'Cache-Control' => 'public, max-age=86400' 
    },
    File.open('public/index.html', File::RDONLY)
  ]
}
Run Code Online (Sandbox Code Playgroud)

如何为此添加HTTP Basic Auth?奖励积分,如果它只适用于生产环境.

谢谢

ruby rack heroku basic-authentication

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

使用tomcat基本身份验证从Web应用程序注销

我正在为我的网络应用程序使用tomcat基本身份验证:

我在web应用程序中向web.xml添加了以下行:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>webpages</web-resource-name>
            <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>*</role-name>
    </auth-constraint>

    <user-data-constraint>
        <!-- transport-guarantee can be CONFIDENTIAL, INTEGRAL, or NONE -->
        <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
</security-constraint>

<login-config>
    <auth-method>BASIC</auth-method>
</login-config>
<security-role>
    <role-name>*</role-name>
</security-role>
Run Code Online (Sandbox Code Playgroud)

我的退出链接:

<h:commandLink value="Logout" action="#{userBean.logout}" />
Run Code Online (Sandbox Code Playgroud)

我的注销链接操作:

public void logout() throws IOException
{
    FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
    FacesContext.getCurrentInstance().getExternalContext().redirect("add_international_job.faces");
}
Run Code Online (Sandbox Code Playgroud)

现在,当调用logout时,它会重定向到另一个应该要求身份验证的页面.但是它会在用户登录时呈现.PS:当用户第一次在地址栏中键入同一页面的URL时,会向他显示身份验证质询(这意味着在保护页面密码时没有问题) .

apache tomcat basic-authentication jsf-2

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

Python SOAP客户端,使用suds的WSDL调用为HTTP基本身份验证提供了传输错误401未授权

背景

我正在使用python 2.7.3构建一个SOAP客户端,并使用Canonical提供的suds 0.4.1库.服务器正在使用HTTPS进行基本身份验证.

问题

无法在服务器上传递身份验证,甚至无法获取WSDL.我收到以下错误:

suds.transport.TransportError:HTTP错误401:未经授权

尝试解决方案和代码

我已经尝试了suds文档中描述的两种身份验证方法,但仍然client = Client(url, ...)在行上面得到了错误.我已经确认了在Web浏览器中连接的凭据和功能,这很好.

声明之后wsdl_url,usernamepassword,我想:

client = Client(url=wsdl_url, username=username, password=password)

# as well as:

t = HttpAuthenticated(username=username, password=password)
client = Client(url=wsdl_url, transport=t)

# and even:

t = HttpAuthenticated(username=username, password=password)
t.handler = urllib2.HTTPBasicAuthHandler(t.pm)
t.urlopener = urllib2.build_opener(t.handler)
client = Client(url=wsdl_url, transport=t)
Run Code Online (Sandbox Code Playgroud)

最后一个似乎至少在另一个关于使用suds进行HTTP身份验证的问题中从WSDL URL获得响应.

其他说明

这个问题与这个类似的问题截然不同,因为我正在使用:

from suds.transport.https import HttpAuthenticated
# not:
# from suds.transport.http import HttpAuthenticated
Run Code Online (Sandbox Code Playgroud)

从Traceback中,这个client = Client(url, …

python soap wsdl suds basic-authentication

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

如何在JavaScript中使用JIRA REST API进行基本身份验证?

我正在为智能电视创建一个JavaScript应用程序,以便在电视上显示仪表板.我获得了使用JIRA REST API的仪表板列表.我用它的网址是:

jira/rest/api/2/dashboard?startAt=&maxResults=
Run Code Online (Sandbox Code Playgroud)

之后我创建了一个墙板,然后在电视上显示:

jira/plugins/servlet/Wallboard/?dashboardId=&os_username=&os_password=
Run Code Online (Sandbox Code Playgroud)

因为os_usernameos_password,JIRA知道我已经过身份验证并获得了正确的列表.这个列表是我从一开始就需要的,但因为我用参数调用上面的url os_username,os_password它确实得到了正确的列表

但是在启动电视时/我第一次获得JIRA的仪表板列表时,没有人通过认证,所以它需要一个随机列表,而不是我需要的列表.

有一些方法可以使用以下命令在JIRA中进行身份验证:

curl -D- -u fred:fred -X GET -H "Content-Type: application/json"         http://example.com/rest/api/2/issue/createmeta
Run Code Online (Sandbox Code Playgroud)

但我不知道如何在JavaScript中使用该命令.

因此,任何人都可以告诉我如何使用基本身份验证在JIRA中进行身份验证,非常重要的是有JAVASCRIPT.

javascript authentication curl jira basic-authentication

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

如何在node.js客户端中执行Auth

我想通过身份验证来使用这个rest api.我正在尝试包括标题但没有得到任何回复.它抛出的输出通常在没有认证时抛出.谁能建议我一些解决方案.下面是我的代码

var http = require('http');

var optionsget = {
    host : 'localhost', // here only the domain name

    port : 1234,

    path:'/api/rest/xyz',
            headers: {
     'Authorization': 'Basic ' + new Buffer('abc'+ ':' + '1234').toString('base64')
   } ,
    method : 'GET' // do GET

};

console.info('Options prepared:');
console.info(optionsget);
console.info('Do the GET call');

var reqGet = http.request(optionsget, function(res) {
    console.log("statusCode: ", res.statusCode);

    res.on('data', function(d) {
        console.info('GET result:\n');
        process.stdout.write(d);
        console.info('\n\nCall completed');
    });

});

reqGet.end();
reqGet.on('error', function(e) {
    console.error(e);
});
Run Code Online (Sandbox Code Playgroud)

basic-authentication node.js node.js-client

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

c# - 使用https和基本身份验证的http Web请求

我正在尝试通过基本身份验证的https网址进行webrequest.而它不工作!下面是我的代码,它实际上工作,如果我使用非安全网址与安全网址,我无法弄清楚我做错了什么.工作只是找到非安全,但当使用安全网址时,我得到401用户身份验证错误.是否有人在服务器上设置错误,或者是我的代码?

有人能帮助我吗?

        var req = System.Net.HttpWebRequest.Create(Url) as HttpWebRequest;
        req.Method = Method.ToString();
        req.ContentType = "application/json";
        req.Date = RequestTime;
        req.Proxy = null;
        string credentials = String.Format("{0}:{1}", "xxxx", "xxxx");
        byte[] bytes = Encoding.ASCII.GetBytes(credentials);
        string base64 = Convert.ToBase64String(bytes);
        string authorization = String.Concat("Basic ", base64);
        req.Headers.Add("Authorization", authorization);
        HttpWebResponse response = (HttpWebResponse)req.GetResponse();
    Stream receiveStream = response.GetResponseStream();

        StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
        string responsebody = readStream.ReadToEnd();
        Console.WriteLine(responsebody);

        response.Close();
        readStream.Close();
Run Code Online (Sandbox Code Playgroud)

c# https webrequest httpwebrequest basic-authentication

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

如何让iOS Safari保存基本认证网站的密码?

我目前正在开发一个使用https基本身份验证的网站

一些使用iOS Safari的客户抱怨Safari不要求保存密码.

似乎iOS Safari只在网站实现基于表单的身份验证时才要求保存密码.

我不想在所有设备上安装第三方浏览器或应用程序来解决此问题.

那么,有没有办法强制iOS Safari为基本身份验证网站保存密码?

security safari https basic-authentication ios

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

perl6中的基本身份验证与Cro

我正在寻找一个简单的解决方案来保护我的路线与基本认证机制与Cro.在我的例子中,我想看看401 Unauthorized如果你根本不提供任何凭据.如果您提供错误的凭据,我希望看到一个403 Forbidden

在我的代码示例中,我从未看到MyBasicAuth被调用的中间件:

class MyUser does Cro::HTTP::Auth {
    has $.username;
}

subset LoggedInUser of MyUser where { .username.defined }

class MyBasicAuth does Cro::HTTP::Auth::Basic[MyUser, "username"] {
    method authenticate(Str $user, Str $pass --> Bool) {
        # No, don't actually do this!
        say "authentication called";
        my $success = $user eq 'admin' && $pass eq 'secret';
        forbidden without $success;
        return $success
    }
}

sub routes() is export {
    my %storage;
    route {
        before MyBasicAuth.new;
        post -> LoggedInUser $user, …
Run Code Online (Sandbox Code Playgroud)

basic-authentication perl6 cro

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