Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ CHANGELOG
7.0.7 (unreleased)
------------------

- Nothing changed yet.
- feat: create reCAPTCHA validation utility
Comment thread
rboixaderg marked this conversation as resolved.
[rboixaderg]
Comment thread
rboixaderg marked this conversation as resolved.


7.0.6 (2025-10-10)
Expand Down
5 changes: 5 additions & 0 deletions guillotina/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
"factory": "guillotina.async_util.AsyncJobPool",
"settings": {"max_size": 5},
},
"guillotina.recaptcha": {
"provides": "guillotina.interfaces.IRecaptchaValidationUtility",
"factory": "guillotina.auth.recaptcha.RecaptchaValidator",
"settings": {},
},
},
"store_json": True,
"pickle_protocol": pickle.HIGHEST_PROTOCOL,
Expand Down
30 changes: 17 additions & 13 deletions guillotina/api/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from guillotina import configure
from guillotina.api.service import Service
from guillotina.auth import authenticate_user
from guillotina.auth.recaptcha import RecaptchaValidator
from guillotina.auth.utils import find_user
from guillotina.component import get_utility
from guillotina.component import query_utility
Expand All @@ -21,6 +20,8 @@
from guillotina.response import HTTPUnauthorized
from guillotina.utils import get_authenticated_user
from json.decoder import JSONDecodeError
from guillotina.interfaces.async_util import IRecaptchaValidationUtility


import json
import jwt
Expand Down Expand Up @@ -240,10 +241,11 @@ async def __call__(self):
raise HTTPNotAcceptable()
else:
# We validate with recaptcha
validator = RecaptchaValidator()
status = await validator.validate()
if status is False:
raise HTTPUnauthorized(content={"text": "Invalid validation"})
recaptcha_validator = get_utility(IRecaptchaValidationUtility)
if recaptcha_validator is not None:
status = await recaptcha_validator.validate()
if status is False:
raise HTTPUnauthorized(content={"text": "Invalid validation"})

# We need to validate is a valid user
user = await find_user({"id": user_id})
Expand Down Expand Up @@ -338,10 +340,11 @@ async def __call__(self):
if allowed is False:
raise HTTPUnauthorized(content={"text": "Not allowed registration"})

validator = RecaptchaValidator()
status = await validator.validate()
if status is False:
raise HTTPUnauthorized(content={"text": "Invalid validation"})
recaptcha_validator = get_utility(IRecaptchaValidationUtility)
if recaptcha_validator is not None:
status = await recaptcha_validator.validate()
if status is False:
raise HTTPUnauthorized(content={"text": "Invalid validation"})

payload = await self.request.json()

Expand Down Expand Up @@ -398,10 +401,11 @@ async def __call__(self):
)
class InfoAccess(Service):
async def __call__(self):
validator = RecaptchaValidator()
status = await validator.validate()
if status is False:
raise HTTPUnauthorized(content={"text": "Invalid validation"})
recaptcha_validator = get_utility(IRecaptchaValidationUtility)
if recaptcha_validator is not None:
status = await recaptcha_validator.validate()
if status is False:
raise HTTPUnauthorized(content={"text": "Invalid validation"})

auth_providers = app_settings.get("auth_providers", {})
providers = []
Expand Down
1 change: 0 additions & 1 deletion guillotina/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .groups import GroupsUtility # noqa
from .recaptcha import RecaptchaValidator # noqa
from .utils import authenticate_request # noqa
from .utils import authenticate_user # noqa
from .utils import find_user # noqa
Expand Down
1 change: 1 addition & 0 deletions guillotina/interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .async_util import ICacheUtility # noqa
from .async_util import IPubSubUtility # noqa
from .async_util import IQueueUtility # noqa
from .async_util import IRecaptchaValidationUtility # noqa
from .async_util import ISessionManagerUtility # noqa
from .behaviors import IAsyncBehavior # noqa
from .behaviors import IBehavior # noqa
Expand Down
5 changes: 5 additions & 0 deletions guillotina/interfaces/async_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@ async def refresh_session(ident: str, session: str) -> str:
"""
Refresh an actual session
"""


class IRecaptchaValidationUtility(IAsyncUtility):
Comment thread
rboixaderg marked this conversation as resolved.
async def validate() -> bool:
Comment thread
rboixaderg marked this conversation as resolved.
pass
Loading