jetbridge / flask_cognito

Flask authentication with JWT against AWS Cognito
MIT License
94 stars 30 forks source link

Ensure identity_callback is defined before checking to see if it is set #24

Closed joshfriend closed 3 years ago

joshfriend commented 3 years ago

WIth the following basic app sample, the error AttributeError: 'CognitoAuth' object has no attribute 'identity_callback' is thrown when trying to register an identity handler:

app = Flask()
ca = CognitoAuth()

@ca.identity_handler
def handler(payload):
    return None

This PR ensures that the identity_callback property that is being checked exists when registering an identity handler, because it currently does not until init_app is called.

revmischa commented 3 years ago

Thanks!

joshfriend commented 3 years ago

as it turns out, while this was a step in the right direction, using the identity_handler as a decorator as shown above and in the README example still does not work for late-init apps because ca.init_app(app) sets the callback to None again unless you pass the callback to init_app:

ca = CognitoAuth()

def handler(payload):
    return none

app = Flask()
ca.init_app(app, identity_handler=handler)