IndominusByte / fastapi-jwt-auth

FastAPI extension that provides JWT Auth support (secure, easy to use, and lightweight)
http://indominusbyte.github.io/fastapi-jwt-auth/
MIT License
627 stars 143 forks source link

Using AuthJWT for token creation only? #75

Open vaizki opened 2 years ago

vaizki commented 2 years ago

I have an OAuth2 password flow authorization endpoint which is used to create a token. However if I inject AuthJWT as a dependency, the request will fail as there is an Authorization: Basic <basicauth in base64> header in the request, containing client_id and client_secret.

I would still like to use the utility functions create_access_token etc. So currently I just derive a dummy class like this:

class DummyAuthJWT(AuthJWT):
    def __init__(self, req = None, res = None):
        pass

.. and inject that so that I don't get the header verification exception.

Is there a cleaner way to access the token creation only?

Midnighter commented 2 years ago

I have a similar need. I would like to generate tokens for an API service using a command line tool. So neither a request nor response will ever exist. Will try it with such a wrapper class.