dorinclisu / fastapi-auth0

FastAPI authentication and authorization using auth0.com
MIT License
230 stars 37 forks source link

Make Auth0User load generically in Auth0 #3

Closed danielSanchezQ closed 3 years ago

danielSanchezQ commented 3 years ago

The idea is that tokens can have different payload metadata. It is interesting to be able to set the pydantic model to deserialize dynamically when creating the auth object. Most probably this model will inherit from the base Auth0User lib model.

danielSanchezQ commented 3 years ago

@dorinclisu I'm not sure why tests are failing though. Does them need some service that is not up? It should be transparent changes from your implementation.

dorinclisu commented 3 years ago

Sorry, it seems that any merge request would fail due to the way github environment secrets are restricted. I'll try to fix this and then I'll have a look at your code.

dorinclisu commented 3 years ago

I had to disable the actual tests for pull requests, because I don't see any way to perform meaningful testing without calling auth0 api, which requires secret credentials available only for approved collaborators. But I'm leaving the linting and mypy checks, since they don't involve any API call.

Now to your proposal. I like the idea, as it means you can change the email alias and use your own rule namespace or add other claims according to other rules (didn't investigate more, but I see a bunch of rules available in the dashboard).

The last commit looks fine, leaving Type[BaseModel] certainly wasn't good as user could shoot themselves in the foot by providing a model that doesn't inherit from Auth0User, and then getting unhandled exceptions that lead to the nasty 500 code. But with Type[Auth0User] I suppose the type checker will complain if you pass a random model, right? Might need to add a test for this, though.

dorinclisu commented 3 years ago

Published as 0.1.6

danielSanchezQ commented 3 years ago

Awesome! Thanks!, the library works like a charm 😄