我希望这是一个相对直接的事情,而且我的谷歌技能在这个场合让我失望了.我有一个BASIC身份验证保护资源,我想让PHP执行POST HTTP请求.
我已经尝试将身份验证:基本(加密的u/p数据)注入到看起来不起作用的标题中 - 所以我想知道,Greyskull的功能是否可以表示StackOverflow提供任何指导.
$req .= "&cmd=_initiate_query";
$header = "POST /someendpoint HTTP/1.1\r\n".
"Host:example.com\n".
"Content-Type: application/x-www-form-urlencoded\r\n".
"User-Agent: PHP-Code\r\n".
"Content-Length: " . strlen($req) . "\r\n".
"Connection: close\r\n\r\n";
$fp = fsockopen ('ssl://example.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$result .= fgets ($fp, 128);
}
fclose ($fp);
}
Run Code Online (Sandbox Code Playgroud) 我应该将哪个基本身份验证,摘要身份验证和Oauth用于我的Web应用程序,以允许用户通过Restful API调用访问资源.
取代基本和摘要身份验证不是Oauth更好的解决方案吗?
authentication oauth basic-authentication digest-authentication
我需要从XML-RPC Web服务中获取数据.
new XmlSlurper().parse("http://host/service") 工作正常,但现在我有一个特殊的服务,需要基本的HTTP身份验证.
如何为parse()方法设置用户名和密码,或修改请求的HTTP标头?
使用http://username:password@host/service没有帮助 - 我仍然得到java.io.IOException: Server returned HTTP response code: 401 for URL例外.
谢谢
我有一个配置了Windows身份验证和URL重写的IIS实例,因此它基本上用作反向代理.我的后端服务器(在Linux上运行)需要一个REMOTE_USER标头.是否可以配置IIS以将有关经过身份验证的用户的信息传递给后端服务器?
authentication iis reverse-proxy basic-authentication http-headers
我已经使用Spring MVC构建了一个REST API后端,并使用Spring Security安装了基本的Auth.
我想从Javascript客户端对REST API进行跨域ajax调用.我不想使用JSONP,因为我不想限于GET调用.我使用CORS,我在服务器端放置了正确的标题.
假设我的REST API在域localhost:8087上,我的客户端在localhost:8086上,这是跨域调用.
在我的Javascript客户端中,我使用jQuery进行ajax调用:
<script>
$.ajax ({
url: "http://localhost:8087/SpringMVC/users/user1",
beforeSend: function (xhr) { xhr.setRequestHeader ("Authorization", "Basic xxxxxxxxxxxx"); },
success: function(val) { console.log(val); alert("success" + val); },
error: function(val) { console.log(val); alert("error" + val); }
});
</script>
Run Code Online (Sandbox Code Playgroud)
我的问题是jQuery没有在HTTP请求中发送Authorization标头,我不知道为什么.我不明白因为我在beforeSend方法中这样做,所以它应该在HTTP请求中.结果:我有401错误.
当我尝试从同一域localhost:8087,这不再是跨域的脚本,我没有问题.
这怎么可能 ?
我的脚本只是一个测试.我不打算将我的用户名/密码放在客户端.但我想测试如何对基本的auth保护的REST API进行ajax调用.我想我必须在服务器端发送安全我的用户名/密码,REST API发送给我一个cookie,我不需要再传递用户名/密码,我的下一个ajax调用REST API.我对吗 ?
我已经使用Chrome Advanced REST客户端测试了我的REST API,它就是这样工作的.对于第一个请求,我需要传递授权标头.然后就不需要了.我的javascript网络客户端是否也可以这样工作?我打算使用Node.JS和Backbone来构建它.
非常感谢.
EDIT2:似乎真的是一个CORS浏览器问题.我在服务器端添加了标题Access-Control-Allow-Methods for OPTIONS方法,它适用于Chrome.我可以访问JSON响应,不再出错.但是我仍然需要为下一个请求使用授权标头.如何告诉jQuery使用发送的cookie?
当我尝试使用Firefox 11时,我无法访问json响应并且我有错误:
"NetworkError: 401 Non-Autorisé - http://localhost:8087/SpringMVC/users/user1"
Run Code Online (Sandbox Code Playgroud) jquery spring-security cross-domain basic-authentication cors
这是我在Flask-RESTful中进行单元测试的一部分.
self.app = application.app.test_client()
rv = self.app.get('api/v1.0/{0}'.format(ios_sync_timestamp))
eq_(rv.status_code,200)
Run Code Online (Sandbox Code Playgroud)
在命令行中,我可以使用curl将用户名:密码发送到服务:
curl -d username:password http://localhost:5000/api/v1.0/1234567
Run Code Online (Sandbox Code Playgroud)
如何在单元测试的get()中实现相同的功能?
由于我的get/put/post需要身份验证,否则测试将失败.
python unit-testing basic-authentication flask flask-restful
我在Java中使用一个非常简单的httpServer来进行GET,POST,PUT和DELETE的api休息.我正在使用基本身份验证,我有几个类Authentication.java和Authorisation.java,我用它来验证和检查用户的权限.
所以,问题是我希望所有用户(经过身份验证)能够从我的api休息中获取信息,但只有具有某些特权的用户才能进行POST,PUT和DELETE.那我该怎么办呢?
这就是我得到的
public class Server {
private static HttpServer server;
public static void start() throws IOException {
server = HttpServer.create(new InetSocketAddress(8000), 0);
HttpContext ctx = server.createContext("/users", new UserHandler());
ctx.setAuthenticator(new ApiRestBasicAuthentication("users"));
server.start();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的ApiRestBasicAuthentication
public class ApiRestBasicAuthentication extends BasicAuthenticator {
private UserAuthentication authentication = new UserAuthentication();
public ApiRestBasicAuthentication(String realm) {
super(realm);
}
@Override
public boolean checkCredentials(String user, String pwd) {
int authCode = authentication.authenticate(user, pwd);
return authCode == UserAuthentication.USER_AUTHENTICATED;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,检查凭据仅检查用户是否经过身份验证.但我想检查一下,如果方法是POST,DELETE或PUT,我还应检查具体的凭据.但是如何在ApiRestBasicAuthentication中获取该方法?我在我的处理程序类中这样做
public void handle(HttpExchange httpExchange) throws IOException { …Run Code Online (Sandbox Code Playgroud) 我有一个在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?奖励积分,如果它只适用于生产环境.
谢谢
我目前正在开发一个使用https基本身份验证的网站
一些使用iOS Safari的客户抱怨Safari不要求保存密码.
似乎iOS Safari只在网站实现基于表单的身份验证时才要求保存密码.
我不想在所有设备上安装第三方浏览器或应用程序来解决此问题.
那么,有没有办法强制iOS Safari为基本身份验证网站保存密码?
我正在尝试在已经设置了基本身份验证的 Spring 启动应用程序中配置 CORS。
我在很多地方搜索过,包括这个答案,它指向官方文档中基于过滤器的 CORS 支持。
到目前为止没有运气。
我的 AJAX 请求就是这样完成的。如果从同一来源http://localhost:8080完成,它就可以工作。
fetch('http://localhost:8080/api/lists', {
headers: {
'Authorization': 'Basic dXNlckB0ZXN0LmNvbToxMjM0NQ=='
}
}
Run Code Online (Sandbox Code Playgroud)
AJAX 请求是从http://localhost:3000的 React 应用程序完成的,所以我尝试了以下 Spring boot CORS 配置:
@Configuration
class MyConfiguration {
@Bean
public FilterRegistrationBean corsFilter()
{
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowedOrigins(Arrays.asList("http://localhost:3000"));
// Maybe I can just say "*" for methods and headers
// I just copied these lists from another Dropwizard project
config.setAllowedMethods(Arrays.asList("GET", "PUT", "POST", …Run Code Online (Sandbox Code Playgroud) cors ×2
security ×2
ajax ×1
cross-domain ×1
flask ×1
groovy ×1
heroku ×1
http-headers ×1
https ×1
httpserver ×1
iis ×1
ios ×1
java ×1
jquery ×1
oauth ×1
php ×1
post ×1
python ×1
rack ×1
rest ×1
ruby ×1
safari ×1
spring-boot ×1
unit-testing ×1
xmlslurper ×1