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

后端 未结 22 1461
感情败类
感情败类 2020-11-22 04:00

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 co

22条回答
  •  花落未央
    2020-11-22 04:34

    Sending https://invalid_login@hostname works fine everywhere except Safari on Mac (well, not checked Edge but should work there too).

    Logout doesn't work in Safari when a user selects 'remember password' in the HTTP Basic Authentication popup. In this case the password is stored in Keychain Access (Finder > Applications > Utilities > Keychain Access (or CMD+SPACE and type "Keychain Access")). Sending https://invalid_login@hostname doesn't affect Keychain Access, so with this checkbox it is not possible to logout on Safari on Mac. At least it is how it works for me.

    MacOS Mojave (10.14.6), Safari 12.1.2.

    The code below works fine for me in Firefox (73), Chrome (80) and Safari (12). When a user navigates to a logout page the code is executed and drops the credentials.

        //It should return 401, necessary for Safari only
        const logoutUrl = 'https://example.com/logout'; 
        const xmlHttp = new XMLHttpRequest();
        xmlHttp.open('POST', logoutUrl, true, 'logout');
        xmlHttp.send();
    

    Also for some reason Safari doesn't save credentials in the HTTP Basic Authentication popup even when the 'remember password' is selected. The other browsers do this correctly.

提交回复
热议问题