(20241213) Started accepting "auth" for software/theCaOfficeAi... I don't know how these details count as "auth", though.

This commit is contained in:
2024-12-13 17:01:32 +05:30
parent e8ddffbdfe
commit 4c258b110a
11 changed files with 604 additions and 18 deletions
+27 -4
View File
@@ -34,9 +34,6 @@ import sys
sys.path.append(".")
sys.path.append("..")
# For Quart:
from quart import current_app
# My async utils:
from utils_v2.string import json
from utils_v2.date_time import date_time
@@ -49,6 +46,9 @@ from controllers.base import BaseModel
# Data models:
from models.core.auth_token import CoreAuthTokenModel
# To work with datatypes:
from typing import List
# To work with MongoDB:
from bson import ObjectId
@@ -275,7 +275,7 @@ class AuthTokenController(BaseModel):
) -> CoreAuthTokenModel | None:
"""
To retrieve stored tokens from the database.
To retrieve stored tokens from the database. One token at a time.
:param mongo_conn: The database connection (MongoDB) to use to perform the action.
:param token_id: The identifier granted by the 'get_token_id' method.
:return: The retrieved record that has the token, and information about the service and client if found, else
@@ -291,6 +291,29 @@ class AuthTokenController(BaseModel):
# Done here:
return CoreAuthTokenModel(**token) if token else None
async def get_tokens(
self,
mongo_conn: AsyncMongo,
token_ids: List[ObjectId | str] = None,
) -> List[CoreAuthTokenModel]:
"""
To retrieve stored tokens from the database. Multiple tokens at a time.
:param mongo_conn: The database connection (MongoDB) to use to perform the action.
:param token_ids: the identifiers granted by the 'get_token_id' method.
:return: The retrieved record that has the token, and information about the service and client if found, else
None when there is no matching record.
"""
# If there is some filtering possible, we fetch the token:
tokens = await mongo_conn.find_many(
collection = self.AUTH_COLLECTION,
filter = {"_id": {"$in": [ObjectId(t) for t in token_ids]}}
)
# Done here:
return [CoreAuthTokenModel(**token) for token in tokens]
# *****************************************************************************************************************
# ***** ****