diff --git a/fastapi_users/authentication/__init__.py b/fastapi_users/authentication/__init__.py index 0e5298a9..51b938e4 100644 --- a/fastapi_users/authentication/__init__.py +++ b/fastapi_users/authentication/__init__.py @@ -152,11 +152,10 @@ class Authenticator: if active and not user.is_active: status_code = status.HTTP_401_UNAUTHORIZED user = None - elif verified and not user.is_verified: + elif ( + verified and not user.is_verified or superuser and not user.is_superuser + ): user = None - elif superuser and not user.is_superuser: - user = None - if not user and not optional: raise HTTPException(status_code=status_code) return user diff --git a/fastapi_users/manager.py b/fastapi_users/manager.py index 1ce00409..d861c507 100644 --- a/fastapi_users/manager.py +++ b/fastapi_users/manager.py @@ -307,7 +307,10 @@ class BaseUserManager(Generic[models.UC, models.UD]): if not user.is_active: raise UserInactive() - token_data = {"user_id": str(user.id), "aud": self.reset_password_token_audience} + token_data = { + "user_id": str(user.id), + "aud": self.reset_password_token_audience, + } token = generate_jwt( token_data, self.reset_password_token_secret, @@ -535,8 +538,7 @@ class BaseUserManager(Generic[models.UC, models.UD]): return user async def _update(self, user: models.UD, update_dict: Dict[str, Any]) -> models.UD: - for field in update_dict: - value = update_dict[field] + for field, value in update_dict.items(): if field == "email" and value != user.email: try: await self.get_by_email(value) diff --git a/fastapi_users/router/oauth.py b/fastapi_users/router/oauth.py index 38b7fa39..ce27bdeb 100644 --- a/fastapi_users/router/oauth.py +++ b/fastapi_users/router/oauth.py @@ -50,11 +50,10 @@ def get_oauth_router( scopes: List[str] = Query(None), ): # Check that authentication_backend exists - backend_exists = False - for backend in authenticator.backends: - if backend.name == authentication_backend: - backend_exists = True - break + backend_exists = any( + backend.name == authentication_backend for backend in authenticator.backends + ) + if not backend_exists: raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST) diff --git a/tests/test_authentication.py b/tests/test_authentication.py index 30e62f32..d8ddf9e0 100644 --- a/tests/test_authentication.py +++ b/tests/test_authentication.py @@ -137,5 +137,5 @@ async def test_authenticator_none_enabled(get_test_auth_client, user): @pytest.mark.asyncio async def test_authenticators_with_same_name(get_test_auth_client): with pytest.raises(DuplicateBackendNamesError): - async for client in get_test_auth_client([BackendNone(), BackendNone()]): + async for _ in get_test_auth_client([BackendNone(), BackendNone()]): pass