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

[PLAT-149] Enforce wallet fetch ordering in discovery auth_middleware #3145

Merged
merged 2 commits into from
May 25, 2022
Merged
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
9 changes: 9 additions & 0 deletions discovery-provider/src/utils/auth_middleware.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import functools
import logging

from eth_account.messages import encode_defunct
from flask.globals import request
from src.models.models import User
from src.utils import db_session, web3_provider

logger = logging.getLogger(__name__)

MESSAGE_HEADER = "Encoded-Data-Message"
SIGNATURE_HEADER = "Encoded-Data-Signature"

Expand Down Expand Up @@ -50,10 +53,16 @@ def inner_wrap(*args, **kwargs):
User.wallet == wallet.lower(),
User.is_current == True,
)
# In the case that multiple wallets match (not enforced on the data layer),
# pick the user id that is lowest (created first).
.order_by(User.user_id.asc())
.first()
)
if user:
authed_user_id = user.user_id
logger.info(
f"auth_middleware.py | authed_user_id: {authed_user_id}"
)
return func(*args, **kwargs, authed_user_id=authed_user_id)

return inner_wrap
Expand Down