(20241221) Zerodha Auth Ready. Users can now integrate Kite.
This commit is contained in:
@@ -103,6 +103,10 @@ class CoreAuthTokenController(CoreBaseModel):
|
||||
# For MongoDB:
|
||||
AUTH_COLLECTION = "_authTokens"
|
||||
|
||||
# Other variables:
|
||||
_service_type = None
|
||||
_client = None
|
||||
|
||||
# ┏┓
|
||||
# ┃ ┏┓┏┓┏╋┏┓┓┏┏╋┏┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┛ ┗┻┗┗┗┛┛
|
||||
@@ -166,6 +170,12 @@ class CoreAuthTokenController(CoreBaseModel):
|
||||
:return: An ObjectId to later store the granted tokens.
|
||||
"""
|
||||
|
||||
# Safety check for consistency:
|
||||
if self._service_type is not None and self._service_type != auth_token.serviceType:
|
||||
raise ValueError(f"Expected service type '{self._service_type}', got '{auth_token.serviceType}'")
|
||||
if self._client is not None and self._client != auth_token.client:
|
||||
raise ValueError(f"Expected service type '{self._client}', got '{auth_token.client}'")
|
||||
|
||||
# Note down the timestamp at which this event occurred:
|
||||
request_ts = date_time.get_current_utc_date_time(as_string = False)
|
||||
|
||||
@@ -255,6 +265,12 @@ class CoreAuthTokenController(CoreBaseModel):
|
||||
:return: True if saved, False if failed.
|
||||
"""
|
||||
|
||||
# Safety check for consistency:
|
||||
if self._service_type is not None and self._service_type != auth_token.serviceType:
|
||||
raise ValueError(f"Expected service type '{self._service_type}', got '{auth_token.serviceType}'")
|
||||
if self._client is not None and self._client != auth_token.client:
|
||||
raise ValueError(f"Expected service type '{self._client}', got '{auth_token.client}'")
|
||||
|
||||
# Start by assuming failure:
|
||||
token_saved = False
|
||||
|
||||
@@ -430,6 +446,33 @@ class CoreAuthTokenController(CoreBaseModel):
|
||||
# Done here:
|
||||
return CoreAuthTokenModel(**token) if token else None
|
||||
|
||||
async def get_token_from_filter(
|
||||
self,
|
||||
mongo_data_conn: AsyncMongo,
|
||||
filter_json: dict
|
||||
) -> CoreAuthTokenModel | None:
|
||||
|
||||
"""
|
||||
To retrieve stored tokens from the database. One token at a time.
|
||||
:param mongo_data_conn: The database connection (MongoDB) to use to perform the action.
|
||||
:param filter_json: The filter conditions to use.
|
||||
: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.
|
||||
"""
|
||||
|
||||
# Prepare the filter:
|
||||
if self._base_filter:
|
||||
for k, v in self._base_filter.items(): filter_json[k] = v
|
||||
|
||||
# If there is some filtering possible, we fetch the token:
|
||||
token = await mongo_data_conn.find_one(
|
||||
collection = self.AUTH_COLLECTION,
|
||||
filter = filter_json
|
||||
)
|
||||
|
||||
# Done here:
|
||||
return CoreAuthTokenModel(**token) if token else None
|
||||
|
||||
async def get_tokens_from_ids(
|
||||
self,
|
||||
mongo_data_conn: AsyncMongo,
|
||||
|
||||
Reference in New Issue
Block a user