jetbridge / flask_cognito

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

Using Flask_Cognito with add_url_rule() #5

Open laayis opened 5 years ago

laayis commented 5 years ago

Hi am very new to flask. How can one use this library with the add_url_rule() method for authentication?

app.add_url_rule( '/example', #the endpoint view_func=GraphQLView.as_view( #setting the view function 'lta',

we set the schema that we generate

    schema=schema, 
    #we say that we do want to use graphqli interface
    graphiql=True))
revmischa commented 5 years ago

I'm not positive but maybe try view_func= cognito_auth_required(GraphQLView.as_view( ...

revmischa commented 5 years ago

a decorator is just a function that takes a function and returns a function

cdominguezg commented 4 years ago

Yes, you can do as @revmischa says. I've done something like this but in a separate function:

def graphql_view():
    view = GraphQLView.as_view('graphql', schema=schema, graphiql=True)
    return cognito_auth_required(view)

app.add_url_rule('/graphql', view_func=graphql_view())