Skip to content
Discussion options

You must be logged in to vote

The App/Request contexts are added when the on_... method is invoked, so that is correct, the trigger_event method does not have access. You can fix this easily by triggering a fake event:

class SecurityNamespace(Namespace):

    def trigger_event(self, event, *args):
        super().trigger_event('catchall', event, *args)

    def on_catchall(event, *args):
        if event == "connect":
            print("custom namespace for access control")
            # get endpoint
            user=g.user #get "Working outside of application context"
            endpoint = self.namespace
            if check_access(user, endpoint):
                super().trigger_event(event, *args)
            else:…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@cis1124
Comment options

@miguelgrinberg
Comment options

Answer selected by cis1124
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants