tokusumi / fastapi-cloudauth

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

Specify to work with localstack or Cognito Local for local testing? #86

Open lay-z opened 6 months ago

lay-z commented 6 months ago

Not so much an issue as a question, i wanted to work with a local cognito provider while running my service locally before connecting to cognito in production. I noticed I wasn't able to specify a local host url, looking closer into the code looks like its all hardcoded in the Cognito object. Is there anyway for me to specify the url or would i have to create a PR?

class Cognito(ScopedAuth):
    """
    Verify access token of AWS Cognito
    """

    user_info = None

    def __init__(
        self,
        region: str,
        userPoolId: str,
        client_id: str,
        scope_key: Optional[str] = "cognito:groups",
        auto_error: bool = True,
    ):
        url = f"https://cognito-idp.{region}.amazonaws.com/{userPoolId}/.well-known/jwks.json"
        jwks = JWKS(url=url)
        super().__init__(
            jwks,
            audience=client_id,
            issuer=f"https://cognito-idp.{region}.amazonaws.com/{userPoolId}",
            scope_key=scope_key,
            auto_error=auto_error,
            extra=CognitoExtraVerifier(
                client_id=client_id,
                issuer=f"https://cognito-idp.{region}.amazonaws.com/{userPoolId}",
                token_use={"access"},
            ),
        )