[Python] Python Flask can't access app inside Blueprint

Discussão em 'Python' iniciado por Stack, Junho 5, 2025.

  1. Stack

    Stack Membro Participativo

    I've been trying to build a keycloak oidc authentication flow with flask.

    Before using oidc, I need to initialize the oidc variable inside my /auth blueprint. I can't get it running.

    from flask import Blueprint, current_app
    from flask_oidc import OpenIDConnect

    auth = Blueprint('auth', __name__, static_folder="static", template_folder="templates")

    app = current_app._get_current_object()

    with app.app_context():
    oidc = OpenIDConnect(app)


    I am getting the following error:

    RuntimeError: Working outside of application context.


    What can I do to use the OpenIDConnect inside the Blueprint? I know similar questions have already been asked multiple times but I can't get it running with their solutions.

    Continue reading...

Compartilhe esta Página