JS

JAVASCRIPT FETCH WITH HTTP BASIC AUTH

URL & CREDENTIALS var url = "protected/secret.html",       creds = btoa("USER:PASS");

FETCH WITH HTTP BASIC AUTH

01

FETCH WITH HTTP AUTH fetch (url, {   headers: { "Authorization": `Basic    ${creds}` }  }) .then((res) => {   if (res.status != 200) { throw "Bad    Response"; }   return res.text(); }) .then((res) => { console.log(res); });

.HTACCESS AuthType Basic AuthName "Password Required" AuthUserFile FOLDER\.htpasswd Require valid-user

BASIC AUTH WITH APACHE

02

RUN HTACCESS IN COMMAND LINE  htpasswd -c "PATH/FOLDER/.htpasswd" USER