5

I am creating a HTTP Server in node js, and I want to add a password to a page that only I will use. The Basic authentication scheme requires username and password (In the browser popup). Having a username is useless for me and I want to know if its even possible to just show a password dialog.

The current code is this, sending a Status Code 401 and the WWW-Authenticate header.

response.statusCode = 401;
response.setHeader('WWW-Authenticate', 'Basic realm="Requires Password"');
response.end();

Which creates this window in Firefox

Authentication Window

So what do I need to change in the response headers to only have a password field?

ImDaveead
  • 311
  • 3
  • 7

1 Answers1

8

I want to know if its even possible to just show a password dialog.

No. The Basic authentication scheme is based on the model that the client needs to authenticate itself with a username and a password for each protection space, frequently referred as realm.

For a response with 401 and WWW-Authenticate with the value Basic, the browser will prompt for both username and password.

So what do I need to change in the response headers to only have a password field?

If, for some reason, you don't want the username, you can leave it empty, pick a default one or choose another authentication scheme that suit your needs.

Community
  • 1
  • 1
cassiomolin
  • 124,154
  • 35
  • 280
  • 359