Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the HTTP Basic Auth username from javascript?

I have a webpage that is only accessible over http basic auth. How can I figure out the basic auth username in javascript in that page. i.e. when someone visits it (after logging in), I want to make a popup that says "Hello, you're currently signed in as the user $USERNAME"

like image 248
Amandasaurus Avatar asked Aug 11 '10 15:08

Amandasaurus


2 Answers

It's not possible purely from JavaScript. You'd have to have the server side script pick up the username from the request, and insert it in the generated page code for the script to pick up. (eg. <script type="text/javascript">var username=(insert JSON-encoded string here);</script>.

like image 186
bobince Avatar answered Oct 22 '22 04:10

bobince


javascript:window.alert(document.location) seems to give a URL with a username (but no password). This may not be true in other browsers.

like image 33
tc. Avatar answered Oct 22 '22 06:10

tc.