Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pure JavaScript code for HTTP Basic Authentication?

Where can I find reference code that implements a HTTP Basic Authentication client in pure JavaScript, suitable for AJAX?

Extra points for code, or pointers to code, that can be used independent of JS toolkits like YUI. No points for Java, Flash/Flex, PHP frameworks, etc.

like image 947
system PAUSE Avatar asked Jan 29 '09 14:01

system PAUSE


People also ask

How do you authenticate in JavaScript?

To setup Authentication, the user needs to configure OAuth 2.0 ID in JavaScript and the backend code. 5. JavaScript application uses client ID to obtain the Google ID token from OAuth 2.0 server and send ID in the request.

How do I get http authentication?

A client that wants to authenticate itself with the server can then do so by including an Authorization request header with the credentials. Usually a client will present a password prompt to the user and will then issue the request including the correct Authorization header.


1 Answers

The five-parameter version of the XMLHttpRequest.open method allows you to specify the username and password. (WHATWG spec)

xhr.open(method, url, async, username, password) 
like image 99
Alnitak Avatar answered Sep 22 '22 13:09

Alnitak