0

I'm looking to get a login page set up to redirect traffic to a different URI on the same server. This is proving somewhat difficult and hours of Googling hasn't turned up much.

I currently have a web application that I've set up which uses .htpasswd files within Apache. I'm looking to create a html login page which will display a login form. On a button click, it should add the base64 encoded authorization header and redirect the page to my web app. In doing so this will bypass the horrid 401 panel requesting the login details.

I currently have the following index.html within my /login directory

<!DOCTYPE html>
<html>
<head>
<title>My Title</title>
<link href="style.css" rel="stylesheet" type="text/css">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function Login(form) {
var username = form.username.value;
var password = form.password.value; 
var server = form.server.value;
if (username && password && server) {
var htsite = "http://" + username + ":" + password + "@" + server;
window.location = htsite;
}
else {
alert("Please enter your username and password.");
   }
}
//  End -->
</script>
</head>
<body>
<form name=login>
<input type="hidden" name="server" value="myserver.co.uk/shell">
Username:
<input type=text name=username size=20>
<br><br>
Password:
<input type=password name=password size=20>
<input type=button value="Login!" onClick="Login(this.form)" name="button">
</form>
</body>
</html>

This is attempting to redirect to http://username:password@myserver.co.uk/shell

This form of basic authentication within the URL no longer seems to work within most browsers.

Is there ANY way of creating and adding in the request header in to the HTTP request redirect?

If you have any suggestions on methods I could use then that would be brilliant. I'm willing to go down any avenue with this, if it requires me to install any extra components then I'll happily give it a go!

Thanks as always.

Will Ryan
  • 661
  • 1
  • 7
  • 17
  • Have you tried on your target app change your auth logic to redirect all incoming traffic to a js script (or whatever you like) to receive the auth params and set a sesion cookie? then login into your app. – Giancarlo Benítez Apr 27 '17 at 14:47
  • You can do the authentication in the header, see https://en.wikipedia.org/wiki/Basic_access_authentication See this for more info http://stackoverflow.com/questions/28589224/javascript-redirect-url-with-authorization-header –  May 03 '17 at 11:21

0 Answers0