GitHub user bohdan-pd edited a comment on the discussion: Accessing 
TaskInstances from DagRun context after Airflow 3.x API changes

```

from airflow.api_fastapi.auth.tokens import JWTGenerator


def get_api_credentials(self):
    """Get API base URL and token."""
    airflow_environment = Variable.get("environment", default="LOCAL")
    base_url = os.environ.get("MWAA__CORE__API_SERVER_URL", 
"http://localhost:8080";)

    if airflow_environment != "local":
        mwaa_api_user_id = Variable.get("mwaa_api_user_id", default="2")
        generator = JWTGenerator(
            secret_key=conf.get("api_auth", "jwt_secret"),
            valid_for=conf.getint("api_auth", "jwt_token_ttl", fallback=86400),
            audience=conf.get("api_auth", "jwt_audience", 
fallback="apache-airflow"),
            issuer=conf.get("api_auth", "jwt_issuer", fallback=None),
            algorithm=conf.get("api_auth", "jwt_algorithm", fallback="HS512")
        )
        token = generator.generate({"sub": str(mwaa_api_user_id)})
    else:
        token = ""
    return base_url, token
```

Hi @dmanikhine, it's MWAA related, but for your deployment, it might work 
differently 

GitHub link: 
https://github.com/apache/airflow/discussions/56037#discussioncomment-15146645

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]

Reply via email to