k4black / fastapi-jwt

FastAPI native extension, easy and simple JWT auth
https://k4black.github.io/fastapi-jwt/
MIT License
127 stars 19 forks source link

Support standard JWT payload #26

Open JoshuaMathias opened 11 months ago

JoshuaMathias commented 11 months ago

I found 3 significant issues that directly prevented me from using this library for decoding a JWT token that was created by separate code:

  1. Specifying "aud" as audience and "iss" as issuer to jose's decode function, as well as any other kwargs that jose supports. This can now be done with a decode_kwargs parameter.
  2. Use of the standard "sub" instead of "subject" for subject. I made "sub" the default so this change could affect existing applications that already have tokens generated, but you can also specify subject_key="subject".
  3. Instead of only returning subject and jti in the credentials payload available to the API code, return the whole payload so all data is available. I implemented this by having JwtAuthorizationCredentials inherit from dict and represent the payload directly.

After the above fixes, I was able to get my use case to work.

Example use: access_security = JwtAccessBearer(secret_key='your-secret-key'), auto_error=True, decode_kwargs={"audience": "My-Service", "issuer": "whoever made the key"}, subject_key="sub")

Since this repository doesn't appear to be maintained and I need this right away, this is now found on pip at https://pypi.org/project/fastapi-jwt-extended/1.0.0/ pip install fastapi_jwt_extended