Forcing Oauth2 logout?

I have an app using Oauth2 (Azure) where the tokens expire quite quickly.
If the code discovers a token is expired/unusable for one reason or another, I want to force a logout.

There doesn’t seem to be a “nice” way to accomplish this, but I am far from a Panel expert so I’m hoping for some hints :slight_smile:

I’ve fixed it by making an invisible ReactiveHTML component with a value trigger that does window.location = '/logout' (as well as a trigger if value > 0 on render to catch if it was expired before the app was served) and it works decently, but it feels somewhat hackish.

Another idea I threw around was having a reactivehtml component delete the cookies, then reload the page, but that’s not really particularly better.

Is there a better way to do it?

Can you please share your work? I wish to reproduce similar approach.

My component is something like this:

class LogoutComponent(ReactiveHTML):
    value = param.Integer(default=0)

    _template = ""

    _scripts = {
        "value": """
          window.location = '/logout'
        "after_layout": """
          if (data.value > 0) {
            window.location = '/logout';

def logout(self):
    self.value += 1

I basically just add it to the template’s header container. Then call logout when I need to logout.
It does it both on value change and on after_layout to ensure it’ll work if it’s logout was called before the component was renderered (which in the design of this app can happen easily.)

I’m not convinced this is a particularly great solution, but I needed to move on to do actual work :wink:
I unfortunately can’t share the actual solution for the OAuth2 issues. I ended up creating a custom oauth-provider for panel which does a bunch of magic to make things work.

Would it work on a MaterialTemplate?

Don’t see why not, but I have no idea. I used BootstrapTemplate.