Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I http-authentication login with javascript for an iframe?

I need to make a page that will

  1. Login to a site automatically via http-authentication
  2. Show said site with an iframe

I was thinking I could use XHR and specify the login headers directly, and then use javascript to create the iframe. Does this make sense? Will it work?

like image 594
Frew Schmidt Avatar asked Jan 27 '26 14:01

Frew Schmidt


1 Answers

Due to the same-origin-policy your XHR approach won't work.

However, for HTTP authentication you can simply include the data in the url, i.e. the src of the <iframe>:

<iframe src="http://username:[email protected]/..."></iframe>

I think I don't have to mention that this should not be done if the login credentials are sensitive - they are likely to show up in the browser history.

like image 154
ThiefMaster Avatar answered Jan 29 '26 04:01

ThiefMaster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!