Jsoup connection with basic access authentication

With HTTP basic access authentication you need to send the Authorization header along with a value of “Basic ” + base64encode(“username:password”). E.g. String username = “foo”; String password = “bar”; String login = username + “:” + password; String base64login = Base64.getEncoder().encodeToString(login.getBytes()); Document document = Jsoup .connect(“http://example.com”) .header(“Authorization”, “Basic ” + base64login) .get(); // … … 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

Adding Basic Authorization for Swagger-UI

Swagger UI 3.x In Swagger UI 3.13.0+, you can use the preauthorizeBasic method to pre-fill the Basic auth username and password for “try it out” calls. Assuming your API definition includes a security scheme for Basic auth: swagger: ‘2.0’ … securityDefinitions: basicAuth: type: basic security: – basicAuth: [] you can specify the default username and … Read more

How to use http.client in Node.js if there is basic authorization

You have to set the Authorization field in the header. It contains the authentication type Basic in this case and the username:password combination which gets encoded in Base64: var username=”Test”; var password = ‘123’; var auth=”Basic ” + Buffer.from(username + ‘:’ + password).toString(‘base64’); // new Buffer() is deprecated from v6 // auth is: ‘Basic VGVzdDoxMjM=’ … 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

ASP.NET MVC – HTTP Authentication Prompt

Well, to require basic authentication you need to return 401 status code. But doing that will cause the current authentication module to execute its default unauthorized handler (for forms authentication, this means redirecting to login page). I wrote an ActionFilterAttribte to see if I can get the behaviour you want when there’s no authentication module … Read more