标签: basic-authentication

尝试包含自定义模块时加载错误

相同的应用程序,不同的问 我正在使用Dan Benjamin"Meet Sinatra"截屏视频作为参考.我正在尝试包含一个自定义身份验证模块,它位于lib文件夹(lib/authentication.rb)中.我要求代码顶部的那行,但是当我尝试加载页面时,它声称没有这样的文件要加载.

有什么想法吗?

这是我的主要Sinatra文件的顶部:

require 'sinatra'
require 'rubygems'
require 'datamapper'
require 'dm-core'
require 'lib/authorization'

DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/entries.db")

class Entry
include DataMapper::Resource

property :id,           Serial
property :first_name,   String
property :last_name,    String
property :email,        String
property :created_at,   DateTime    

end

# create, upgrade, or migrate tables automatically
DataMapper.auto_upgrade!

helpers do
include Sinatra::Authorization
end
Run Code Online (Sandbox Code Playgroud)

而实际的模块:

module Sinatra
  module Authorization

  def auth
    @auth ||= Rack::Auth::Basic::Request.new(request.env)
  end

  def unauthorized!(realm="Short URL Generator")
    headers 'WWW-Authenticate' => %(Basic realm="#{realm}")
    throw :halt, [ 401, 'Authorization Required' ]
  end

  def …
Run Code Online (Sandbox Code Playgroud)

ruby basic-authentication sinatra

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

使用WCF通过HTTPS进行基本HTTP身份验证

我通过WCF(w/.NET 4.0)调用Web服务,该服务需要通过HTTPS进行基本HTTP身份验证(使用用户名和密码.).虽然,我认为我已经正确设置了所有内容,但每当我打电话给服务时,我都会收到401错误.我监视了HTTP流量,并注意到WCF似乎忽略了我告诉它使用带有用户名和密码的授权标头,因为在请求中没有发送.这是我的配置如下.有任何想法吗?谢谢!

   <system.serviceModel>
         <bindings>
                <basicHttpBinding>
                       <binding name="BasicAuthSecured">
                             <security mode="Transport">
                                    <transport clientCredentialType="Basic" />
                             </security>
                       </binding>
                       </basicHttpBinding>
                </bindings>
         <client>
                <endpoint address="https://REMOVED FOR CONFIDENTIALITY"
            binding="basicHttpBinding" bindingConfiguration="BasicAuthSecured"
            contract="Five9.WsAdmin" name="WsAdminPort" />
         </client>
         <behaviors>
                <serviceBehaviors>
                       <behavior name="">
                             <serviceMetadata httpsGetEnabled="true"/>
                             <serviceDebug includeExceptionDetailInFaults="true"/>
                       </behavior>
                </serviceBehaviors>
         </behaviors>
   </system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

        var five_9_client = new WsAdminClient();

        five_9_client.ClientCredentials.UserName.UserName = “REMOVED FOR CONFIDENTIALITY";
        five_9_client.ClientCredentials.UserName.Password = "REMOVED FOR CONFIDENTIALITY";

        var call_log_response = five_9_client.getCallLogReport(call_log); //Bombing out here
Run Code Online (Sandbox Code Playgroud)

我得到了这个例外:

{"HTTP请求未经授权,客户端身份验证方案为'Basic'.从服务器收到的身份验证标头为''."}

内部异常:

{"远程服务器返回错误:(401)未经授权."}

使用堆栈跟踪:

在System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest的请求,响应HttpWebResponse,引发WebException responseException,HttpChannelFactory工厂)在System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest的请求,响应HttpWebResponse,HttpChannelFactory工厂,引发WebException responseException,ChannelBinding channelBinding)在在System.ServiceModel.Dispatcher.RequestChannelBinder.Request的System.ServiceModel.Channels.RequestChannel.Request(消息消息,TimeSpan超时)中的System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)(消息消息,TimeSpan超时) )System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs,TimeSpan …

https wcf basic-authentication

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

将SQL Server连接的密码缓存为哈希

我正在编写一个.NET 4.0应用程序,需要访问Intranet上的SQL Server(v10.50.1600)数据库.该数据库不支持集成安全性/ SSPI登录,仅支持用户/密码登录.我到目前为止所做的最好的是:

SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder()
{
   DataSource = Settings.SQLHostName,
   Encrypt = true,
   TrustServerCertificate = true,
   UserID = Settings.SQLUser,
   Password = "xxx",
   InitialCatalog = "xxx"
};
Run Code Online (Sandbox Code Playgroud)

但是,这需要我在本地存储和操作纯文本密码,这是我想要避免的.

有没有办法给ADO,LINQ或实体框架等提供密码哈希而不是密码来连接到SQL Server?


虽然连接字符串的加密存储总比没有好,但最终需要在使用前解密.由于在WPF密码框上没有可绑定内容属性背后的基本原理显然是将明文密码保存在内存中是一个坏主意,使用前任何类型的连接字符串解密听起来都是不明智的.

理想的替代方案是了解SQL服务器如何存储和传输其密码摘要; 在本地应用相同的摘要算法; 然后发送摘要而不是明文密码.不幸的是,似乎部分描述了TDS7密码编码:

http://dbaspot.com/ms-sqlserver/210567-tds7-8-login-packets.html

好像根本没有使用任何摘要算法.所以我可能会坚持使用podiluska的答案.

.net sql-server hash password-protection basic-authentication

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

用401理解基本认证

我对Web浏览器的基本身份验证有点困惑.我原以为Web浏览器只会在上一个响应中收到HTTP 401状态后发送Authorization标头.但是,Chrome似乎会随后向每个请求发送Authorization标头.它有一次我输入的数据,以响应我网站上的401,并随每条消息一起发送(根据Chrome和我的网络服务器附带的开发人员工具).这是预期的行为吗?是否有一些标题我应该用我的401来推断授权的东西不应该被缓存?我目前正在使用WWW-Authenticate标头.

iis basic-authentication http-headers wcf-data-services http-status-code-401

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

当我设置错误的凭据时,为什么我的http basic auth请求获得状态0?Phonegap Android

在我使用phonegap制作的Android应用程序中,用户可以登录.当他们这样做时,JQuery获取他们的登录名和密码,并根据HTTP Basic Auth规范使用他们的凭据进行ajax调用.一切正常.
但是,当用户设置错误的凭据时,我遇到了处理这种情况的问题.在.error()回调中,我想显示状态401的特定消息(如"身份验证失败")和其他状态的消息("技术问题").我的代码:

$.ajax({
                url: "http://exemple.com",
                type: "GET",
                dataType: "text",
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                beforeSend: function (xhr)
                {
                    xhr.setRequestHeader("Authorization", "Basic "+$.base64.encode(email+":"+password));
                },
                success: function() {
                    //my success callback
                },
                error: function(xhr) {
                    if(xhr.status===401) {
                        //"authentication failed"
                    }
                    else {
                        //"technical problem"
                    }
                }
            });
Run Code Online (Sandbox Code Playgroud)

此代码在浏览器中正常工作.状态401被发送.但是,当我在我的phonegap android应用程序中测试时,状态发送为0.当我的凭据良好时,状态发送为200,而我的应用程序的其他请求运行良好,所以我不认为这是一个cors问题.

任何的想法 ?谢谢你的帮助

jquery android xmlhttprequest basic-authentication cordova

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

StructureMap,Web Api 2和IUserStore错误

我刚刚开始尝试使用Web Api 2和StructureMap,已经安装了StructureMap.MVC4 Nuget包.在我尝试注册用户之前,一切似乎都运行良好.当IHttpControllerActivator的这个实现试图实例化一个控制器时,我得到了这个错误:

public class ServiceActivator : IHttpControllerActivator
    {
        public ServiceActivator(HttpConfiguration configuration) { }

        public IHttpController Create(HttpRequestMessage request
            , HttpControllerDescriptor controllerDescriptor, Type controllerType)
        {
            var controller = ObjectFactory.GetInstance(controllerType) as IHttpController;
            return controller;
        }
    }
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

StructureMap Exception Code:  202
No Default Instance defined for PluginFamily Microsoft.AspNet.Identity.IUserStore`1[[Microsoft.AspNet.Identity.EntityFramework.IdentityUser, Microsoft.AspNet.Identity.EntityFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], Microsoft.AspNet.Identity.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Run Code Online (Sandbox Code Playgroud)

我理解错误是什么,但不完全确定如何解决它.假设StructureMap中的默认扫描程序找不到IUserStore的默认实现是否正确?这是我使用的初始化代码:

ObjectFactory.Initialize(x => x.Scan(scan =>
            {
                scan.AssembliesFromApplicationBaseDirectory();
                scan.WithDefaultConventions();
            }));
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?谢谢.

编辑:我想我可能用这个解决了最初的问题:

x.For<Microsoft.AspNet.Identity.IUserStore<IdentityUser>>()
                    .Use<UserStore<IdentityUser>>();
Run Code Online (Sandbox Code Playgroud)

但现在还有另一个默认实例StructureMap无法解决 - dbcontext.这是我收到的下一条错误消息:

ExceptionMessage=StructureMap Exception Code:  202
No Default Instance defined for …
Run Code Online (Sandbox Code Playgroud)

structuremap dependency-injection basic-authentication asp.net-web-api

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

自定义身份验证筛选器(实现IAuthenticationFilter)未触发

我有一个ASP MVC 5应用程序,我无法使自定义身份验证筛选器工作.

我在"CustomFilters"文件夹中创建了一个自定义身份验证过滤器,如下所示:

public class CustomBasicAuthAttribute : ActionFilterAttribute, IAuthenticationFilter
{

    public void OnAuthentication(AuthenticationContext context)
    {
        // does not fire... :(
    }

    public void OnAuthenticationChallenge(AuthenticationChallengeContext context)
    {
        // does not fire... :(
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的ProductController中,我装饰了以下方法之一:

public class ProductsController : ApiController
{

    [CustomBasicAuth]
    [HttpGet]
    [Route("clients/{id}/products")]
    public IEnumerable<Products> GetByClientId(int id)
    {

        return new List<Products>();
    }
Run Code Online (Sandbox Code Playgroud)

但是,出于某种原因,CustomBasicAuth类中的OnAuthentication方法永远不会触发.我试图装饰整个控制器,并尝试全局加载它,但没有一个工作.

我阅读并关注了大量有关此问题的在线文章,看起来这应该可行.

任何帮助将不胜感激.

asp.net-mvc basic-authentication asp.net-mvc-5

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

在Axis2中找不到HttpTransportProperties.Authenticator

刚刚使用Apache Axis 2从WSDL生成Java代码.该服务受基本身份验证保护.当我尝试创建身份验证对象以设置用户名和密码时,HttpTransportProperties.Authenticator在库中找不到class().

如何为Apache Axis2生成的客户端代码设置基本身份验证?

以下是设置基本身份验证参数的旧方法:

HttpTransportProperties.Authenticator basicAuth = new HttpTransportProperties.Authenticator();
basicAuth.setUsername("username");
basicAuth.setPassword("password");
basicAuth.setPreemptiveAuthentication(true);

final Options clientOptions = stub._getServiceClient().getOptions();
clientOptions.setProperty(HTTPConstants.AUTHENTICATE, basicAuth);
stub._getServiceClient().setOptions(clientOptions);
Run Code Online (Sandbox Code Playgroud)

java axis axis2 web-services basic-authentication

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

Nginx HTTP基本身份验证,特定IP地址除外

我正在为运行的Web应用程序设置基本身份验证。

该应用程序使用nginx 1.12.2以及Apache 2.2.15(尽管这是一个测试实例,而生产实例使用1.12.2和2.4.6)。它们都在CentOS 7服务器上运行。

我一直在这里使用教程来做到这一点。我设法使身份验证正常工作,并且在浏览器中导航至该站点时,弹出对话框询问用户名和密码。但是,我无法使用IP白名单-无论我从哪里连接都要求提供凭据。

目的是使我们网络上或通过我们的VPN连接的任何人都不必输入这些凭据。似乎应该很简单,但我无法使其正常工作。

本质上,我们需要192.168.1.1-192.168.1.255范围内的任何人都可以访问它,以及10.8.0.x范围内的VPN地址。

在尝试IP地址控件之前,我必须处理nginx conf文件中的位置,然后放置身份验证信息以使其起作用,并发现它必须位于我添加的部分中。但是,IP控件不起作用就像声明的那样。我看不到我在这里想念的东西。

以下是内容 /etc/nginx/sites-available/myapp.conf

upstream myapplication-3.3.2 {
        server 127.0.0.1:18805;
}

server {
  listen 80;
  server_name mydomain.com;
  location '/.well-known/acme-challenge' {
    default_type "text/plain";
    root  /srv/letsencrypt;
  }
  location / {
    return 301 https://$server_name$request_uri;
  }
}

server {
        listen 18804;
        location / {
                return 301 https://$host$request_uri;
        }
}


server {
        listen 80;
        location / {
                return 301 https://$host$request_uri;
        }
}

server {
        listen 443 ssl;
        server_name mydomain.com;

        access_log /var/log/nginx/myapplication3.access.log;
        error_log /var/log/nginx/myapplication3-errors.log;

        ssl on;
        ssl_certificate_key …
Run Code Online (Sandbox Code Playgroud)

nginx basic-authentication

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

groovy-下载带有身份验证的文件

我需要使用Groovy使用基本身份验证(一种提示浏览器要求您输入域\用户名和密码的身份验证)下载文本文件。我想避免使用其他库,在Groovy中没有做任何事情吗?

我当前的代码是:

new File("test.txt").withOutputStream { out ->
    def url = new URL(myurl).openConnection()

    def remoteAuth = "Basic " + "myusername:mypassword".bytes.encodeBase64()
    url.setRequestProperty("Authorization", remoteAuth);
    out << url.inputStream
}
Run Code Online (Sandbox Code Playgroud)

但是服务器回复401错误。我该怎么办?

authentication groovy http httprequest basic-authentication

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