我想检查一个URL是否受到使用javascript的Http基本身份验证的保护.这是我到目前为止:
function showFailure(){ alert("FAILED ") }
function showSuccess(){ alert("SUCCESS") }
var myRequest = new Request({
url: 'http://localhost/access_protected_HTTP_BASIC',
method: 'get',
onSuccess: showSuccess,
onFailure: showFailure
}).send();
Run Code Online (Sandbox Code Playgroud)
但这实际上打开了浏览器登录弹出窗口以访问资源.有没有办法不触发弹出窗口?
谢谢!
注意:我在这个例子中使用mootools,但我会采取任何javascript示例,这样做:)
对于这个认证业务,我是一个新手.所以我一直在寻找,但找不到任何直接的解决方案:
我使用Devise gem为用户身份验证和iPhone前端获得了Rails后端.我需要知道如何从iPhone创建用户.
我已经掌握了如何创建异步帖子的资源,但是我需要更好地理解HTTP身份验证的一般概念 - 例如,如果我使用Curl创建一个帖子来创建一个利用基本HTTP的用户身份验证,我将发送给'www.example.com/createuser'的curl命令是什么?
对于这个例子,我的Rails应用程序的用户模型属性是电子邮件和密码.
万分感谢您提供任何建议/资源链接.我非常感谢!
最好,贾里德
从我使用的JavaScript:
xhr.setRequestHeader("Authorization", make_base_auth(username,password));
Run Code Online (Sandbox Code Playgroud)
但是,HTTP请求没有Authorization标头:
OPTIONS /restService/index?_=1362589672203 HTTP/1.1
Host: myappinheroku.herokuapp.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: es-MX,es-ES;q=0.8,es-AR;q=0.7,es;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Origin: http://127.0.0.1:8081
Access-Control-Request-Method: GET
Access-Control-Request-Headers: authorization,content-type
Connection: keep-alive
Run Code Online (Sandbox Code Playgroud)
似乎完全忽略了身份验证.怎么了?我们如何为CORS启用身份验证?
这是服务器对上述请求的响应:
HTTP/1.1 401 Full authentication is required to access this resource
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: origin, authorization, accept, content-type, x-requested- with
Access-Control-Allow-Methods: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Server: Jetty(7.x.y-SNAPSHOT)
Set-Cookie: JSESSIONID=6smxjnlqelmc1lg98ain16wv7;Path=/
WWW-Authenticate: Basic realm="Ralph's Bait and Tackle"
Transfer-Encoding: chunked
Connection: …Run Code Online (Sandbox Code Playgroud) 如何在Django中使用Spyne的基本身份验证?我尝试了以下但它不起作用.我可以很好地查看WSDL页面文件,但每当我真正尝试将SayHello称为Web服务时,我都会收到403 FORBIDDEN响应.我相信403与CSRF有关,但csrf_exempt不应该让我解决这个问题吗?BTW,logged_in_or_basicauth来自这个片段:http://djangosnippets.org/snippets/243/.
class CapsWebService(ServiceBase):
@rpc(String, Integer, _returns=Iterable(String))
def SayHello(ctx, name, times):
for i in xrange(times):
yield 'Hello, %s' % name
caps_web_service = csrf_exempt(DjangoApplication(Application(
[CapsWebService], 'solutions.sfcs', in_protocol=Soap11(), out_protocol=Soap11(), interface=Wsdl11(),
)))
@logged_in_or_basicauth()
def foo_view(request):
logger.debug('views.foo_view()')
return caps_web_service(request)
Run Code Online (Sandbox Code Playgroud) 我在基本auth procted文件夹中的子文件夹有问题.在受保护的文件夹中,我有一个名为phpmyadmin的文件夹,其中包含phpmyadmin.当基本激活时,我无法运行phpmyadmin.当我调用该文件夹时,我得到一个另存为对话框(类型:application/octet-stream(18,3 KB)).
这里是mysites的重要部分 - 可用/默认
location ^~ /administration/ {
auth_basic "Restricted Area";
auth_basic_user_file /var/www/myproject/sec/htpasswd;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
Run Code Online (Sandbox Code Playgroud)
任何想法,我如何在基本认证保护子文件夹中运行php?
我正在使用ASP.NET Web API构建Web服务(和站点)的原型,该原型具有下载文件的方法.当前端的用户按下导出按钮时,控制器发出并接收jQuery ajax GET请求,然后控制器调用名为Excel的方法(如下所示).该方法运行没有任何问题并完成.当我在标题中查看Chrome时(请参阅https://skydrive.live.com/redir?resid=2D85E5C937AC2BF9!77093),它会收到响应(据我所知)所有正确的标题.
我正在使用Basic Auth,因此使用http授权头传输用户凭据,我已使用Ajax选项手动将其添加到每个jQuery Ajax请求中.
var excelRequest = $.ajax({
url: 'http://localhost:59390/api/mycontroller/excel',
cache: false,
type: 'GET',
data: gridString,
dataType: 'json',
contentType: 'application/json; charset=utf-8'
});
$.ajaxSetup({
beforeSend: function (xhr) {
SetAuthRequestHeader(xhr)
}
});
function SetAuthRequestHeader(jqXHR) {
var usr = "Gebruiker2"; // TODO: Change, this is for testing only.
var pw = "Wachtwoord23";
jqXHR.setRequestHeader("Authorization", "Basic " + Base64.encode(usr + ":" + pw));
}
Run Code Online (Sandbox Code Playgroud)
我的原型有一些我应该提到的特征:
在Authorization标头中使用Basic Auth
Web服务和调用该服务的网站位于不同的域中,因此我使用CORS并将以下内容添加到web.config中
Run Code Online (Sandbox Code Playgroud)<httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> <add name="access-control-allow-headers" value="Content-Type, Authorization, Accept" …
c# asp.net basic-authentication asp.net-mvc-4 asp.net-web-api
我正在运行Flask Web应用程序并使用Apache基本身份验证(使用.htaccess和.htpasswd文件)来对其进行密码保护.我想密码保护应用程序中的一个网页.当我用密码保护网页的html文件时没有任何效果,网页仍然没有密码保护.这可能是因为我的python文件是使用render_template调用html文件的吗?我不知道如何解决这个问题.
维基百科说,HTTP基本身份验证依赖于Authorization标头来提供从客户端到服务器的凭据.
但也可以在URL中嵌入凭据:
http(s)://<user>:<password>@<host>/<path>
Run Code Online (Sandbox Code Playgroud)
它是由浏览器解释并转换为Authorization标题还是直接发送到服务器?
我正在尝试使用BasicHttpBinding和使用用户名/密码进行身份验证来设置WCF Web服务。我做了自定义认证类。但是,它永远不会被调用(通过调试验证)。这是我的web.config:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<behaviors>
<serviceBehaviors>
<behavior>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Compareware_WebApp.webservices.AuthenticationValidator, Compareware_WebApp" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding">
<security mode="TransportCredentialOnly">
<message clientCredentialType="UserName" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="Compareware_WebApp.webservices.Accounts">
<endpoint address="/webservices/Accounts.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding" name="BasicEndpoint"
contract="Compareware_WebApp.webservices.IAccounts" />
</service>
</services>
<client />
Run Code Online (Sandbox Code Playgroud)
这是我的身份验证类:
namespace Compareware_WebApp.webservices
Run Code Online (Sandbox Code Playgroud)
{
public class AuthenticationValidator : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if (null == userName || null == password) …Run Code Online (Sandbox Code Playgroud) 我使用Spring Security进行基本身份验证来保护我的REST API.
以下是配置代码:
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user")
.password("password")
.roles("admin");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.anyRequest().authenticated();
}
}
Run Code Online (Sandbox Code Playgroud)
我在使用正确的用户名和密码验证自己时遇到了禁止(403)错误.
请建议修改以使其正常工作.