Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate passing in anonymous_user class. #865

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Fixes
- (:issue:`859`) Update Quickstart to show how to properly handle SQLAlchemy connections.
- (:issue:`861`) Auth Token not returned from /tf-validate. (thanks lilz-egoto)
- (:pr:`864`) Fix for latest email_validator deprecation - bump minimum to 2.0.0
- (:pr:`xxx`) Deprecate passing in the anonymous_user class (sent to Flask-Login).

Version 5.3.1
-------------
Expand Down
12 changes: 0 additions & 12 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ Core

A proxy for the current user.

.. function:: flask_security.Security.unauthorized_handler

If an endpoint fails authentication or authorization from one of the decorators
described below
(except ``login_required``), a method annotated with this decorator will be called.
For ``login_required`` (which is implemented in Flask-Login) use
**flask_security.login_manager.unauthorized_handler**

.. deprecated:: 3.3.0

Protecting Views
----------------
.. autofunction:: flask_security.anonymous_user_required
Expand Down Expand Up @@ -147,8 +137,6 @@ Utils

.. autofunction:: flask_security.send_mail

.. autofunction:: flask_security.get_token_status

.. autofunction:: flask_security.check_and_get_token_status

.. autofunction:: flask_security.get_url
Expand Down
2 changes: 1 addition & 1 deletion flask_security/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@
)
from .webauthn_util import WebauthnUtil

__version__ = "5.3.1"
__version__ = "5.3.2"
17 changes: 13 additions & 4 deletions flask_security/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,11 +1108,12 @@ class Security:
``send_mail`` and ``send_mail_task``. Replaced with ``mail_util_cls``.
``two_factor_verify_password_form`` removed.
``password_validator`` removed in favor of the new ``password_util_cls``.

.. deprecated:: 5.0.0
Passing in a LoginManager instance. Removed in 5.1.0
.. deprecated:: 5.0.0
json_encoder_cls is no longer honored since Flask 2.2 has deprecated it.
.. deprecated:: 5.3.1
Passing in an anonymous_user class.
"""

def __init__(
Expand Down Expand Up @@ -1172,7 +1173,7 @@ def __init__(
warnings.warn(
"kwargs passed to the constructor are now ignored",
DeprecationWarning,
stacklevel=4,
stacklevel=2,
)
self.app = app
self._datastore = datastore
Expand Down Expand Up @@ -1220,7 +1221,7 @@ def __init__(

# Attributes not settable from init.
self._unauthn_handler: t.Callable[
[t.List[str], t.Optional[t.Dict[str, str]]], "ResponseValue"
..., "ResponseValue"
] = default_unauthn_handler
self._reauthn_handler: t.Callable[
[timedelta, timedelta], "ResponseValue"
Expand Down Expand Up @@ -1390,6 +1391,14 @@ def init_app(
if kwargs.get(attr, None):
setattr(self, attr, kwargs.get(attr))

if self.anonymous_user:
warnings.warn(
"Passing in an anonymous_user class for use with Flask-Login"
"was deprecated in 5.3.2 and will be removed in 5.4",
DeprecationWarning,
stacklevel=2,
)

# set all (SECURITY) config items as attributes (minus the SECURITY_ prefix)
for key, value in get_config(app).items():
# need to start getting rid of this - very confusing.
Expand Down Expand Up @@ -1871,7 +1880,7 @@ def reauthn_handler(
def unauthorized_handler(self, cb: t.Callable[[], "ResponseValue"]) -> None:
warnings.warn(
"'unauthorized_handler' has been replaced with"
" 'unauthz_handler' and 'unauthn_handler'",
" 'unauthz_handler' and 'unauthn_handler' and will be removed in 5.4",
DeprecationWarning,
stacklevel=2,
)
Expand Down
2 changes: 1 addition & 1 deletion flask_security/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def wrapper(*args, **kwargs):
else:
r = _security.default_http_auth_realm if callable(realm) else realm
h = {"WWW-Authenticate": f'Basic realm="{r}"'}
return _security._unauthn_handler(["basic"], h)
return _security._unauthn_handler(["basic"], headers=h)

return wrapper

Expand Down