我是新来的api's并通过.NET调用它们
我有一个api:https://sub.domain.com/api/operations? param = value & param2 = value
api的注释说要授权我需要使用基本的访问身份验证 - 我该怎么做?
我目前有这个代码:
WebRequest req = WebRequest.Create(@"https://sub.domain.com/api/operations?param=value¶m2=value");
req.Method = "GET";
//req.Credentials = new NetworkCredential("username", "password");
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
Run Code Online (Sandbox Code Playgroud)
但是我得到了401未经授权的错误.
我缺少什么,如何使用基本访问身份验证形成api呼叫?
我正在使用带有Java配置的Spring-Security 3.2.0.RC2.我设置了一个简单的HttpSecurity配置,要求/ v1/**上的基本身份验证.GET请求工作但POST请求失败:
HTTP Status 403 - Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'.
Run Code Online (Sandbox Code Playgroud)
我的安全配置如下所示:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Resource
private MyUserDetailsService userDetailsService;
@Autowired
//public void configureGlobal(AuthenticationManagerBuilder auth)
public void configure(AuthenticationManagerBuilder auth)
throws Exception {
StandardPasswordEncoder encoder = new StandardPasswordEncoder();
auth.userDetailsService(userDetailsService).passwordEncoder(encoder);
}
@Configuration
@Order(1)
public static class RestSecurityConfig
extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/v1/**").authorizeRequests()
.antMatchers("/v1/**").authenticated()
.and().httpBasic();
}
}
}
Run Code Online (Sandbox Code Playgroud)
对此的任何帮助都非常感谢.
post csrf spring-security basic-authentication spring-java-config
Chrome 59 删除了对https:// user:password@example.com网址的支持.
我有一个C#selenium测试需要在Windows上以" 无头 "模式使用Chrome版本60
ChromeOptions options = new ChromeOptions();
options.AddArgument("headless");
driver = new ChromeDriver(chrome, options);
Run Code Online (Sandbox Code Playgroud)
这是我试图在Windows上处理的SAML身份验证所需对话框:

基于这里给出的答案:如何使用Java处理Selenium WebDriver的身份验证弹出窗口我可以看到在FireFox中处理此问题的几种解决方法,但在无头模式下Chrome 60没有.
在访问测试中的URL之前,我尝试使用以下代码访问带有凭据的URL(没有凭据)但是看起来Chrome 60 存在错误.
goTo("http://user:password@localhost"); // Caches auth, but page itself is blocked
goTo("http://localhost"); // Uses cached auth, page renders fine
// Continue test as normal
Run Code Online (Sandbox Code Playgroud)
我可以看到Firefox中的以下代码处理身份验证,对话框永远不会弹出:
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("network.automatic-ntlm-auth.trusted-uris", "https://saml.domain.com");
profile.EnableNativeEvents = false;`
Run Code Online (Sandbox Code Playgroud)
我试过(第二种方法使用的AutoIt),以及适用于Chrome 60,但确实不是在Chrome 60工作的无头模式.
//Use AutoIt to …Run Code Online (Sandbox Code Playgroud) c# basic-authentication selenium-chromedriver selenium-webdriver
我正在使用Java BASIC身份验证.
我的Servlet发送了一条JMS消息,但是我需要提供用户和密码来在创建连接时对自己进行身份验证:
javax.jms.ConnectionFactory.createConnection(String username, String password)
Run Code Online (Sandbox Code Playgroud)
我可以从HttpServletRequest.getUserPrincipal()中检索用户名.但似乎无法检索密码.我该如何解决这个问题?
在Python中使用Basic Auth进行HTTP POST的最简洁方法是什么?
仅使用Python核心库.
这是我要做一个简单的GET请求的代码:
var options = {
host: 'localhost',
port: 8000,
path: '/restricted'
};
request = http.get(options, function(res){
var body = "";
res.on('data', function(data) {
body += data;
});
res.on('end', function() {
console.log(body);
})
res.on('error', function(e) {
console.log("Got error: " + e.message);
});
});
Run Code Online (Sandbox Code Playgroud)
但是该路径"/ restricted"需要简单的基本HTTP身份验证.如何添加凭据进行身份验证?我在NodeJS手册中找不到与基本http认证相关的任何内容.提前致谢.
authentication restful-authentication http basic-authentication node.js
我正在尝试使用Google Scripts UrlFetchApp来访问具有基本用户名和密码的网站.一旦我连接到该站点,就会出现需要身份验证的弹出窗口.我知道登录名和密码,但我不知道如何在UrlFetchApp中传递它们.
var response = UrlFetchApp.fetch("htp://00.000.000.000:0000 /");
Logger.log(response.getContentText( "UTF-8"));
当前运行该代码返回"拒绝访问".出于安全原因,上面的代码不包含我要连接的实际地址.代码示例中的所有"http"都缺少"t",因为它们被检测为链接,而Stackoverflow不允许我提交两个以上的链接.
如何将登录名和密码与我的请求一起传递?无论如何我还可以在登录后继续我的会话吗?或者我的下一个UrlFetchApp请求是否会从另一台要求我再次登录的Google服务器发送?
这里的目标是登录Googles网络基础架构背后的网站,以便它可以充当代理,然后我需要向相同的地址发出另一个UrlFetchApp请求,如下所示:
var response = UrlFetchApp.fetch("htp://00.000.000.000:0000/vuze/rpc?json = {"method":"torrent-add","arguments":{"filename":"htp:// vodo达网络/媒体/种子/ anything.torrent " "下载-DIR": "C:\ TEMP"}}");
Logger.log(response.getContentText( "UTF-8"));
login credentials basic-authentication urlfetch google-apps-script
我有一个基于REST的服务器,我试图使用JQuery进行通信.XML和JSON都可用作响应格式,因此我使用的是JSON.
连接都是SSL,因此HTTP基本身份验证是我们选择的授权方法,我们对其他前端没有任何问题(原始Javascript,Silverlight等...)
现在我试图将一些东西与JQuery放在一起,并使用HTTP基本身份验证遇到无穷无尽的问题.
我已经仔细研究了之前的许多问题,其中大部分都有解决方案似乎没有实际工作或将整个问题归咎于跨域访问,我已经在基本的Javascript测试中克服了这些问题.响应始终为Access-Control-Allow-Origin请求中提供的Origin头提供set,这可以在我的测试的响应中看到.
在基本的javascript中,这个完整的调用非常简单:
req.open('GET', 'https://researchdev-vm:8111/card', true, 'test', 'testpassword');
Run Code Online (Sandbox Code Playgroud)
JQuery尝试这是相当标准的:
$.ajax({
username: 'test',
password: 'testpassword',
url: 'https://researchdev-vm:8111/card',
type: 'GET',
dataType: 'json',
crossDomain: true,
/*data: { username: 'test', password: 'testpassword' },*/
beforeSend: function(xhr){
xhr.setRequestHeader("Authorization",
//"Basic " + encodeBase64(username + ":" + password));
"Basic AAAAAAAAAAAAAAAAAAA=");
},
sucess: function(result) {
out('done');
}
});
Run Code Online (Sandbox Code Playgroud)
实际上似乎提供身份验证的唯一方法是在beforeSend()函数中直接插入Base64编码数据.如果不包括在内,则无法取得任何进展.用户名和密码属性似乎完全被忽略.
通过beforeSend()提供的行为,GET调用获得包含数据的肯定响应.但是,因为这是一个跨站点调用,所以OPTIONS调用在GET调用之前执行并始终失败,因为它没有使用,beforeSend()因此由于身份验证失败而获得401响应.
有没有更好的方法来完成应该是一个非常微不足道的电话?OPTIONS请求不使用beforeSend()函数处理的事实应该被视为错误吗?有没有办法完全禁用OPTIONS检查?不可能使这个调用不是跨站点,因为Javascript似乎甚至考虑与"跨站点"在同一台机器上的不同端口号.
javascript ajax jquery http-authentication basic-authentication
在呈现视图之前,是否可以让我的应用程序询问用户名和密码提示?就像在twitter API上获取有关您帐户的信息一样:
http://twitter.com/account/verify_credentials.xml
所以在渲染视图之前|| 文件它要求您插入用户名和密码,我认为这是直接在服务器上进行的,因为curl请求基于用户名:密码以及如下所示:
curl -u user:password http://twitter.com/account/verify_credentials.xml
Run Code Online (Sandbox Code Playgroud)
在我尝试使用相同的结构构建API时,我想知道如何在ASP.NET MVC C#上执行此操作.我已经在ruby rails上使用了它,它非常简单:
before_filter :authenticate
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "foo" && password == "bar"
end
Run Code Online (Sandbox Code Playgroud)
我不认为[授权]过滤器是相同的,因为我认为它只是一个重定向,它将您重定向到基于帐户数据库的帐户内部控制器,在这种情况下,我将使用另一个数据库,特别是从webservice并在提交信息后进行验证.但我需要动作来要求用户并在其请求上传递凭据.
提前致谢
更新:
实际上,要请求一个需要此身份验证的页面(即Twitter),我必须在其请求中声明这一点
request.Credentials = new NetworkCredential("username", "password");
Run Code Online (Sandbox Code Playgroud)
这将反映出提示的用户名和密码.
所以,它是完全相同的,但从另一方面来说,如果可以根据请求向身份验证提示提供信息,我怎么能在请求中要求这种身份验证呢?
因此,每次有人试图通过示例向我的应用程序发出请求:
HTTP://为MyApplication /客户/ verify_credentials
它应该询问服务器提示符的用户名和密码,以便在curl上检索信息,例如它就像这样
curl -u user:password http://myapplication/clients/verify_credentials
Run Code Online (Sandbox Code Playgroud) 我需要为我正在研究的Flash Player项目构建代理.我只需要使用HTTP-Basic身份验证向另一个URL发出HTTP GET请求,并从PHP提供响应,就像PHP文件是原始源一样.我怎样才能做到这一点?