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

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:pass@domain.com to authenticate. For Internet … Read more

Angular 2 Basic Authentication not working

Simplified version to add custom headers to your request: import {Injectable} from ‘@angular/core’; import {Http, Headers} from ‘@angular/http’; @Injectable() export class ApiService { constructor(private _http: Http) {} call(url): Observable<any> { let username: string = ‘username’; let password: string = ‘password’; let headers: Headers = new Headers(); headers.append(“Authorization”, “Basic ” + btoa(username + “:” + password)); … 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

How do I get basic auth working in angularjs?

Assuming your html is defined like this: <!doctype html> <html ng-app=”sandbox-app”> <head> <script src=”https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js”></script> <script src=”todo.js”></script> <link rel=”stylesheet” href=”todo.css”> </head> <body> <h2>Todo</h2> <div ng-controller=”TodoCtrl”> <ol> … </ol> </div> </body> </html> You can make your backend connect to a rest api using basic auth like this: var app = angular.module(‘sandbox-app’, []); app.config(function($httpProvider) { }); app.factory(‘Base64’, function() … Read more

How to prevent browser to invoke basic auth popup and handle 401 error using Jquery?

I was facing this issue recently, too. Since you can’t change the browser’s default behavior of showing the popup in case of a 401 (basic or digest authentication), there are two ways to fix this: Change the server response to not return a 401. Return a 200 code instead and handle this in your jQuery … Read more