Preemptive Basic authentication with Apache HttpClient 4

If you are looking to force HttpClient 4 to authenticate with a single request, the following will work: String username = … String password = … UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password); HttpRequest request = … request.addHeader(new BasicScheme().authenticate(creds, request));

What is the cleanest way to do HTTP POST with basic auth in Python?

Seriously, just use requests: import requests resp = requests.post(url, data={}, auth=(‘user’, ‘pass’)) It’s a pure python library, installing is as easy as easy_install requests or pip install requests. It has an extremely simple and easy to use API, and it fixes bugs in urllib2 so you don’t have to. Don’t make your life harder because … Read more

Basic HTTP authentication in Node.JS?

The username:password is contained in the Authorization header as a base64-encoded string. Try this: const http = require(‘http’); http.createServer(function (req, res) { var header = req.headers.authorization || ”; // get the auth header var token = header.split(/\s+/).pop() || ”; // and the encoded auth token var auth = Buffer.from(token, ‘base64’).toString(); // convert from base64 var … Read more

.htaccess / .htpasswd bypass if at a certain IP address

For versions 2.2.X you can use the following… AuthUserFile /var/www/mysite/.htpasswd AuthName “Please Log In” AuthType Basic require valid-user Order allow,deny Allow from xxx.xxx.xxx.xxx satisfy any Obviously replace the path to your usersfile and the ip address which you would like to bypass the authentication. Further explanation of the specifics, can be found at: http://httpd.apache.org/docs/2.2/howto/auth.html

How do you use Basic Authentication with System.Net.Http.HttpClient?

It looks like you can’t use PostAsync and have access to mess with the Headers for authentication. I had to use an HttpRequestMessage and SendAsync. //setup reusable http client HttpClient client = new HttpClient(); Uri baseUri = new Uri(url); client.BaseAddress = baseUri; client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.ConnectionClose = true; //Post body content var values = new List<KeyValuePair<string, string>>(); … Read more

Spring Security exclude url patterns in security annotation configurartion

Found the solution in Spring security examples posted in Github. WebSecurityConfigurerAdapter has a overloaded configure message that takes WebSecurity as argument which accepts ant matchers on requests to be ignored. @Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers(“/authFailure”); } See Spring Security Samples for more details

API Design: HTTP Basic Authentication vs API Token

Best bet might be using an API key in the header (e.g. ‘Authorization: Token MY_API_KEY’) instead of as a url param: Advantages over HTTP Basic Auth: More convenient, as you can easily expire or regenerate tokens without affecting the user’s account password. If compromised, vulnerability limited to API, not the user’s master account You can … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)