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

后端 未结 22 1421
感情败类
感情败类 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:40

    All you need is redirect user on some logout URL and return 401 Unauthorized error on it. On error page (which must be accessible without basic auth) you need to provide a full link to your home page (including scheme and hostname). User will click this link and browser will ask for credentials again.

    Example for Nginx:

    location /logout {
        return 401;
    }
    
    error_page 401 /errors/401.html;
    
    location /errors {
        auth_basic off;
        ssi        on;
        ssi_types  text/html;
        alias /home/user/errors;
    }
    

    Error page /home/user/errors/401.html:

    
    

    You're not authorised. :///">Login.

提交回复
热议问题