Skip to content

Commit

Permalink
Fix Flask Login user setting for Flask 2.2 and Flask-Login 0.6.2 (#25318
Browse files Browse the repository at this point in the history
)

The Google openid auth backend of ours had hard-coded way of
seting the current user which was not compatible with Flask 2.2

With Flask-login 0.6.2 the user is stored in g module of flask, where
before, it was stored in _request_ctx_stack. Unforatunately the
google_openid rather than using _update_request_context_with_user
set the user directly in context. In Flask-login 0.6.2 this stopped
working.

This change switches to use the _update_request_context_with_user
method rather than directly storing user in context which works before
and after the Flask-Login 0.6.2 change.
  • Loading branch information
potiuk committed Jul 26, 2022
1 parent 7e631a9 commit 8bc1471
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions airflow/providers/google/common/auth_backend/google_openid.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import google
import google.auth.transport.requests
import google.oauth2.id_token
from flask import Response, _request_ctx_stack, current_app, request as flask_request # type: ignore
from flask import Response, current_app, request as flask_request # type: ignore
from google.auth import exceptions
from google.auth.transport.requests import AuthorizedSession
from google.oauth2 import service_account
Expand Down Expand Up @@ -101,8 +101,7 @@ def _lookup_user(user_email: str):


def _set_current_user(user):
ctx = _request_ctx_stack.top
ctx.user = user
current_app.appbuilder.sm.lm._update_request_context_with_user(user=user) # type: ignore[attr-defined]


T = TypeVar("T", bound=Callable)
Expand Down

0 comments on commit 8bc1471

Please sign in to comment.