Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log out user from web site using BASIC authentication?

Is it possible to log out user from a web site if he is using basic authentication?

Killing session is not enough, since, once user is authenticated, each request contains login info, so user is automatically logged in next time he/she access the site using the same credentials.

The only solution so far is to close browser, but that's not acceptable from the usability standpoint.

like image 383
Marko Avatar asked Oct 24 '08 13:10

Marko


People also ask

How do I pass username and password in basic authentication?

1 Answer. It is indeed not possible to pass the username and password via query parameters in standard HTTP auth. Instead, you use a special URL format, like this: http://username:[email protected]/ -- this sends the credentials in the standard HTTP "Authorization" header.

How do you invalidate basic authentication?

Basic Auth credentials are cached until the browser is closed. The problem with logging out from Basic Auth is simple: the browser will cache your credentials by default until the browser windows is closed. There is no standard mechanism to invalidate them.

How do you use login Authentication?

Using HTTP Basic Authentication A client requests access to a protected resource. The Web server returns a dialog box that requests the user name and password. The client submits the user name and password to the server. The server validates the credentials and, if successful, returns the requested resource.

How do I authenticate a login in HTML?

Authentication SchemesThe Form authentication scheme uses a HTML web form for the user to enter their username and password credentials and HTTP Post requests to submit to the server for verification. It may also be used programmatically va HTTP POST requests.


2 Answers

Have the user click on a link to https://log:[email protected]/. That will overwrite existing credentials with invalid ones; logging them out.

like image 98
Matthew Welborn Avatar answered Sep 19 '22 18:09

Matthew Welborn


An addition to the answer by bobince ...

With Ajax you can have your 'Logout' link/button wired to a Javascript function. Have this function send the XMLHttpRequest with a bad username and password. This should get back a 401. Then set document.location back to the pre-login page. This way, the user will never see the extra login dialog during logout, nor have to remember to put in bad credentials.

like image 26
system PAUSE Avatar answered Sep 17 '22 18:09

system PAUSE