Making a HTTP GET request with HTTP-Basic authentication

Marc B did a great job of answering this question. I recently took his approach and wanted to share the resulting code. <?PHP $username = “some-username”; $password = “some-password”; $remote_url=”http://www.somedomain.com/path/to/file”; // Create a stream $opts = array( ‘http’=>array( ‘method’=>”GET”, ‘header’ => “Authorization: Basic ” . base64_encode(“$username:$password”) ) ); $context = stream_context_create($opts); // Open the file … Read more

HttpClientBuilder basic auth

From the Preemptive Authentication Documentation here: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html By default, httpclient will not provide credentials preemptively, it will first create a HTTP request without authentication parameters. This is by design, as a security precaution, and as part of the spec. But, this causes issues if you don’t retry the connection, or wherever you’re connecting to expects … Read more

How to define the basic HTTP authentication using cURL correctly?

curl -u username:password http:// curl -u username http:// From the documentation page: -u, –user <user:password> Specify the user name and password to use for server authentication. Overrides -n, –netrc and –netrc-optional. If you simply specify the user name, curl will prompt for a password. The user name and passwords are split up on the first … Read more

HTTP Basic Auth via URL in Firefox does not work?

I have a solution for Firefox and Internet Explorer. For Firefox, you need to go into about:config and create the integer network.http.phishy-userpass-length with a length of 255. This tells Firefox not to popup an authentication box if the username and password are less than 255 characters. You can now use http://user:[email protected] to authenticate. For Internet … Read more

How do I automatically authorize all endpoints with Swagger UI?

If you use Swagger UI v.3.13.0 or later, you can use the following methods to authorize the endpoints automatically: preauthorizeBasic – for Basic auth preauthorizeApiKey – for API keys and OpenAPI 3.x Bearer auth To use these methods, the corresponding security schemes must be defined in your API definition. For example: openapi: 3.0.0 … components: … 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