inbox-debug-7
This commit is contained in:
parent
cccaf16817
commit
751d91562e
|
@ -28,6 +28,7 @@ async def load_messages(
|
||||||
chat_id: str, limit: int = 5, offset: int = 0, ids: Optional[List[int]] = None
|
chat_id: str, limit: int = 5, offset: int = 0, ids: Optional[List[int]] = None
|
||||||
):
|
):
|
||||||
"""load :limit messages for :chat_id with :offset"""
|
"""load :limit messages for :chat_id with :offset"""
|
||||||
|
logger.info("load_messages")
|
||||||
messages = []
|
messages = []
|
||||||
try:
|
try:
|
||||||
message_ids = [] + (ids or [])
|
message_ids = [] + (ids or [])
|
||||||
|
@ -63,6 +64,7 @@ async def load_messages(
|
||||||
@login_required
|
@login_required
|
||||||
async def load_chats(_, info, limit: int = 50, offset: int = 0) -> Dict[str, Union[List[Dict[str, Any]], None]]:
|
async def load_chats(_, info, limit: int = 50, offset: int = 0) -> Dict[str, Union[List[Dict[str, Any]], None]]:
|
||||||
"""load :limit chats of current user with :offset"""
|
"""load :limit chats of current user with :offset"""
|
||||||
|
logger.info("load_chats")
|
||||||
author_id = info.context["author_id"]
|
author_id = info.context["author_id"]
|
||||||
chats = []
|
chats = []
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -12,29 +12,30 @@ logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
async def check_auth(req) -> str | None:
|
async def check_auth(req) -> str | None:
|
||||||
token = req.headers.get("Authorization")
|
logger.debug("checking auth...")
|
||||||
user_id = ""
|
user_id = ""
|
||||||
if token:
|
try:
|
||||||
# Logging the authentication token
|
token = req.headers.get("Authorization")
|
||||||
query_name = "validate_jwt_token"
|
if token:
|
||||||
operation = "ValidateToken"
|
# Logging the authentication token
|
||||||
headers = {
|
query_name = "validate_jwt_token"
|
||||||
"Content-Type": "application/json",
|
operation = "ValidateToken"
|
||||||
}
|
headers = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
variables = {
|
|
||||||
"params": {
|
|
||||||
"token_type": "access_token",
|
|
||||||
"token": token,
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
gql = {
|
variables = {
|
||||||
"query": f"query {operation}($params: ValidateJWTTokenInput!) {{ {query_name}(params: $params) {{ is_valid claims }} }}",
|
"params": {
|
||||||
"variables": variables,
|
"token_type": "access_token",
|
||||||
"operationName": operation,
|
"token": token,
|
||||||
}
|
}
|
||||||
try:
|
}
|
||||||
|
|
||||||
|
gql = {
|
||||||
|
"query": f"query {operation}($params: ValidateJWTTokenInput!) {{ {query_name}(params: $params) {{ is_valid claims }} }}",
|
||||||
|
"variables": variables,
|
||||||
|
"operationName": operation,
|
||||||
|
}
|
||||||
# Asynchronous HTTP request to the authentication server
|
# Asynchronous HTTP request to the authentication server
|
||||||
async with ClientSession() as session:
|
async with ClientSession() as session:
|
||||||
async with session.post(AUTH_URL, json=gql, headers=headers) as response:
|
async with session.post(AUTH_URL, json=gql, headers=headers) as response:
|
||||||
|
@ -47,9 +48,9 @@ async def check_auth(req) -> str | None:
|
||||||
user_id = data.get("data", {}).get(query_name, {}).get("claims", {}).get("sub")
|
user_id = data.get("data", {}).get(query_name, {}).get("claims", {}).get("sub")
|
||||||
logger.info(f"[services.auth] got user_id: {user_id}")
|
logger.info(f"[services.auth] got user_id: {user_id}")
|
||||||
return user_id
|
return user_id
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Handling and logging exceptions during authentication check
|
# Handling and logging exceptions during authentication check
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
|
||||||
if not user_id:
|
if not user_id:
|
||||||
raise HTTPException(status_code=401, detail="Unauthorized")
|
raise HTTPException(status_code=401, detail="Unauthorized")
|
||||||
|
@ -67,6 +68,9 @@ def login_required(f):
|
||||||
author = get_author_by_user(user_id)
|
author = get_author_by_user(user_id)
|
||||||
if author and "id" in author:
|
if author and "id" in author:
|
||||||
context["author_id"] = author["id"]
|
context["author_id"] = author["id"]
|
||||||
|
else:
|
||||||
|
logger.debug(author)
|
||||||
|
HTTPException(status_code=401, detail="Unauthorized")
|
||||||
return await f(*args, **kwargs)
|
return await f(*args, **kwargs)
|
||||||
|
|
||||||
return decorated_function
|
return decorated_function
|
||||||
|
|
Loading…
Reference in New Issue
Block a user