tokusumi / fastapi-cloudauth

Simple integration between FastAPI and cloud authentication services (AWS Cognito, Auth0, Firebase Authentication).
MIT License
323 stars 35 forks source link

Cognito class instances talk to AWS at import time #47

Open jordan-dimov opened 3 years ago

jordan-dimov commented 3 years ago

Because of code like jwks = JWKS.fromurl(url) in the __init__(), it is impossible to import modules without them trying to connect to AWS Cognito at import time. This can cause a variety of problems, e.g. - unable to run unit tests without an Internet connection.

Minipada commented 3 years ago

Hi @jordan-dimov I was following this issue as I am dealing with edge devices and this is definitely an issue at the moment. Did you close because you found a workaround? If so, could you share?

jordan-dimov commented 3 years ago

@Minipada Oh, good to know it's not just me. I thought maybe I wasn't using it correctly. Ended up creating a fake Cognito class just for my unit tests, and switching between those with an environment variable. Happy to re-open this though.

tivaliy commented 2 years ago

I've faced with the same issue trying to write unittests using moto to fake Cognito resources. And in my case there is no straightforward way to pre-configure environment variable, since I create AWS Cognito resources using fixtures (pytest). Any good ideas how to overcome this?

deanq commented 1 year ago

I have faced the same issue and found a good solution mentioned on another issue here: https://github.com/tokusumi/fastapi-cloudauth/issues/32