0

I need to do a logout button. I use Flask and Python and my website uses basic authentication so as to log in. I found out that the only possible way to log out is to close a browser (which is not what I'm looking for) or to change already entered login and password doing something like this:

user:pass@127.0.0.1:8000

It works when I input that phrase in URL but I'd like to do it programmatically.

My Python code:

@app.route('/logout')
@auth.login_required
def logout():
    urlparameter = "user:pass@127.0.0.1:8000"
    return Response(render_template('logout.html', urlparameter=urlparameter, mimetype='text/html'))

HTML button:

<a href="{{ urlparameter }}">Logout</a>

However, it doesn't work. How should I change it? Thanks

pingwin850
  • 299
  • 1
  • 7
  • 24
  • I guess you want `redirect("http://user:pass@url")` – Joran Beasley Oct 27 '17 at 19:15
  • Yes, I want to redirect and also display a logout.html file and then not be able to browse a website – pingwin850 Oct 27 '17 at 19:30
  • Yes, I've seen this but it doesn't solve my problem.. – pingwin850 Oct 27 '17 at 19:32
  • HTTP Basic Auth is handled by user agent (browser), and basically does not allow logging out (since **each request includes username and password**). To be able to log user out, you have to have a user session. – randomir Oct 27 '17 at 19:34
  • As I said passing different values like e.g. `user:pass@127.0.0.1:8000` allows to (let's say) log out.. I mean when I want to browse my website again I need to enter correct login and password.. I believe it is possible to do using Python and Flask.. – pingwin850 Oct 27 '17 at 19:41

0 Answers0