Skip to content

Commit b2fddcb

Browse files
authored
Replace _app_ctx_stack with g for context storage (#154)
1 parent e878621 commit b2fddcb

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/flask_pyoidc/flask_pyoidc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import flask
2424
import importlib_resources
25-
from flask import _app_ctx_stack, current_app
25+
from flask import current_app, g
2626
from flask.helpers import url_for
2727
from oic import rndstr
2828
from oic.extension.message import TokenIntrospectionResponse
@@ -66,7 +66,7 @@ def __init__(self, provider_configurations, app=None,
6666
# is destroyed between the requests. The value is set by token_auth
6767
# decorator.
6868
self.current_token_identity = LocalProxy(lambda: getattr(
69-
_app_ctx_stack.top, 'current_token_identity', None))
69+
g, 'current_token_identity', None))
7070
self._redirect_uri_config = redirect_uri_config
7171

7272
if app:
@@ -459,7 +459,7 @@ def wrapper(*args, **kwargs):
459459
logger.info('Request has valid access token.')
460460
# Store token introspection info within the application
461461
# context.
462-
_app_ctx_stack.top.current_token_identity = token_introspection_result.to_dict()
462+
g.current_token_identity = token_introspection_result.to_dict()
463463
return view_func(*args, **kwargs)
464464
# Forbid access if the access token is invalid.
465465
flask.abort(403)

tests/test_flask_pyoidc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ def test_token_auth_should_run_view_function_if_valid_token(self):
944944
authn.token_auth(self.PROVIDER_NAME,
945945
scopes_required=['read', 'write'])(view_mock)()
946946
assert view_mock.called
947-
assert flask._app_ctx_stack.top.current_token_identity == token_introspection_response
947+
assert flask.g.current_token_identity == token_introspection_response
948948

949949
@responses.activate
950950
def test_token_auth_should_raise_forbidden_if_invalid_token(self):
@@ -1031,7 +1031,7 @@ def test_access_control_should_run_view_function_if_valid_token(self):
10311031
self.PROVIDER_NAME,
10321032
scopes_required=['read', 'write'])(view_mock)()
10331033
assert view_mock.called
1034-
assert flask._app_ctx_stack.top.current_token_identity == token_introspection_response
1034+
assert flask.g.current_token_identity == token_introspection_response
10351035

10361036
def test_get_url_for_logout_view_should_raise_build_error_if_mounted_under_custom_endpoint(self):
10371037
authn = self.init_app()

0 commit comments

Comments
 (0)