Skip to content

Document how to use Flask decorator with AppFactory/Blueprint pattern #24

@pamelafox

Description

@pamelafox

I had to do this in my create_app function-

with app.app_context():
    app.auth = Auth(
        app,
        authority=os.getenv("AUTHORITY"),
        client_id=os.getenv("CLIENT_ID"),
        client_credential=os.getenv("CLIENT_SECRET"),
        redirect_uri=os.getenv("REDIRECT_URI"),
    )

And then make a wrapper decorator in my Blueprint:

def login_required(f):
    """Decorator to require login for a route."""
    @wraps(f)
    def decorated_function(*args, **kwargs):
        return current_app.auth.login_required(f)(*args, **kwargs)
    return decorated_function

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions