How to redirect to main.py after authenticating the user? (using bokeh authentication hooks)

Hello,

I am new to bokeh and currently building an app that authenticates users and displays few bokeh plots post login. I did go through the https://github.com/bokeh/bokeh/tree/branch-3.0/examples/howto/server_auth toy example, but I am not exactly sure how the redirect to app.py is happening in that example (post login).

My application is using a directory structure so it has a main.py file. I am having difficulty in redirecting the user to the main application post successful login. The post method in LoginHandler is pretty simple and looks like this:

  def post(self):
      server_url = self.get_argument("url", "") 
      username = self.get_argument("username", "")
      password = self.get_argument("password", "")
      auth = self.check_permission(server_url, username, password)
      if auth:
          self.redirect("/")
      else:
         error_msg = "?error=" + tornado.escape.url_escape(self.failure_msg)
         self.redirect(login_url + error_msg)

The check_permission() method validates the credentials and connects to an external API.

@aravind Bokeh’s auth hooks are a very thin wrapper around Tornado’s authentication, so the thing is probably to first look over the Tornado docs regarding auth:

https://www.tornadoweb.org/en/stable/guide/security.html

This is an example.

if auth:
    next_page = self.get_argument('next', None)
    self.redirect(next_page)
else:
    error_msg = "?error=" + tornado.escape.url_escape(self.failure_msg)
    self.redirect(login_url + error_msg)
2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.