flask-apscheduler icon indicating copy to clipboard operation
flask-apscheduler copied to clipboard

How to integrate with Flask-JWT-Extended?

Open lucaam opened this issue 3 years ago • 4 comments

Hello,

I do not find a way to integrate this library with Flask-JWT-Extended I am using in my backend. Does anyone have an example?

It works easily with the basic authentication example in the repo.

lucaam avatar Jun 03 '22 13:06 lucaam

Since the scheduler only runs on a single worker you might find your app works better by using the scheduler as an api that the authenticated app (multi worker) can talk to.

christopherpickering avatar Jun 03 '22 13:06 christopherpickering

What do you mean with "using the scheduler as an api"? I did not get your comment 😔

lucaam avatar Jun 10 '22 18:06 lucaam

Hey, Sorry:

The flask appscheduler can be run as a standalone flask app. This can be separate from your main website. There is an api script: https://viniciuschiele.github.io/flask-apscheduler/rst/api.html

So from your jwt app, a user can be authenticated, and once they are logged in, they can have access to routes that call the API.

I built one here: https://github.com/atlas-bi/atlas-automation-hub, it has a "web app", "scheduler" > using flask app scheduler, and a "runner". My job are normally long running so I split them out from the scheduler so they don't bog it down. I'm happy to chat if you'd like. https://discord.gg/hdz2cpygQD

christopherpickering avatar Jun 10 '22 18:06 christopherpickering

Thanks for the fast response. I started as you did in your project "re-implementing" RestAPI to manage jobs but what I wanted to know is if there is any way to implement a different auth method (JWT instead of HTTPBasicAuth) based on the example here.

For example I expect to initialise scheduler with following parameters

SCHEDULER_API_ENABLED = True SCHEDULER_AUTH = Authentication('bearer')

and use something like the following function to authenticate the RestAPI call

    def authenticate(auth):
        """Check JWT."""
        return is_jwt_valid(auth.get_authorization_header()[1])```

lucaam avatar Jun 10 '22 22:06 lucaam