c022844824
with multiple files added new API for get token details
194 lines
6.8 KiB
Python
194 lines
6.8 KiB
Python
"""
|
|
|
|
AUTHOR:
|
|
|
|
Omkar Khandare
|
|
|
|
DATE:
|
|
|
|
Wednesday, 25rd June., 2025.
|
|
|
|
OBJECTIVE:
|
|
|
|
To disable chat accounts.
|
|
|
|
REFERENCES:
|
|
|
|
N/A
|
|
|
|
DOWNLOADS:
|
|
|
|
N/A
|
|
|
|
NOTES:
|
|
|
|
N/A
|
|
|
|
"""
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** IMPORT ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# To make sibling directories accessible for imports:
|
|
import sys
|
|
|
|
from api.blueprints.common.disable import auth_token_disable_bp
|
|
|
|
sys.path.append(".")
|
|
sys.path.append("..")
|
|
|
|
# For using Quart:
|
|
from quart import Blueprint, current_app, request
|
|
|
|
# My utils:
|
|
from utils_v2.string import json
|
|
from utils_v2.api.codes import StatusCodes, HttpCodes
|
|
from utils_v2.api.response import ResponseModel
|
|
from utils_v2.api.async_quart import (
|
|
set_api_version,
|
|
read_input,
|
|
get_session_info,
|
|
log_request_to_mongo,
|
|
log_chain_to_mongo,
|
|
should_not_be_under_maintenance,
|
|
only_whitelisted_ips,
|
|
limit_rate,
|
|
validate_input,
|
|
handle_cancelled_request
|
|
)
|
|
|
|
# Common:
|
|
from shared import constants
|
|
|
|
# Data Models:
|
|
from models.core.user import CoreUserInfoModel
|
|
from models.api.common.integrations.auth_get import AuthTokenGetRequestData, AuthTokenGetRequestHeaders
|
|
|
|
# Helpers:
|
|
from api.helpers.user import token_check
|
|
|
|
# To work with MongoDB:
|
|
from bson import ObjectId
|
|
|
|
# For asynchronous activities:
|
|
import asyncio
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** MACROS / ONE-TIME INIT ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# Related to Quart:
|
|
integration_get_bp = Blueprint("integration get", __name__)
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** VARIABLES ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# --- Nothing Yet
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** FUNCTIONS ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
@integration_get_bp.record_once
|
|
def init(blueprint_setup_state):
|
|
|
|
# This gets called when the blueprint is registered.
|
|
# Consider this to be a one-time setup for the whole blueprint:
|
|
pass
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------------------------
|
|
|
|
@integration_get_bp.route("/token", methods = ["GET", "POST"])
|
|
@set_api_version(api_version = "1.0.0")
|
|
@read_input(sanitize_headers = False, sanitize_data = False)
|
|
@log_request_to_mongo(
|
|
attr_name = "logs_mongo",
|
|
project = constants.PROJECT_NAME,
|
|
log_type = constants.MODULE_NAME,
|
|
operation = "integrationTokenGetAPI",
|
|
log_input = True,
|
|
log_output = True,
|
|
sensitive_keys = ["sessionToken", "X-Session-Token", "tokenKey"]
|
|
)
|
|
@log_chain_to_mongo(attr_name = "logs_mongo")
|
|
@only_whitelisted_ips(attr_name="whitelisted_ips")
|
|
@should_not_be_under_maintenance(attr_name = "is_under_maintenance")
|
|
@validate_input(
|
|
header_validator = None,
|
|
data_validator = lambda x: AuthTokenGetRequestData(**x)
|
|
)
|
|
@handle_cancelled_request()
|
|
async def get_integrations_token(
|
|
inbound_headers: dict = None,
|
|
inbound_data: dict | AuthTokenGetRequestData = None,
|
|
inbound_files: dict = None,
|
|
**kwargs
|
|
):
|
|
|
|
"""
|
|
Use this when a user wants to remove/disable his account.
|
|
:param inbound_headers: auto-extracted by the decorators.
|
|
:param inbound_data: auto-extracted by the decorators.
|
|
:param inbound_files: auto-extracted by the decorators.
|
|
:param kwargs: Any number of extra inputs supplied by the decorators.
|
|
:return: A standard response structure.
|
|
"""
|
|
print("INBOUND", inbound_data)
|
|
|
|
# ┳┳┓ ┓•┏ ┏┓
|
|
# ┃┃┃┏┓┏┫┓╋┓┏ ┗┓╋┏┓╋┓┏┏
|
|
# ┛ ┗┗┛┗┻┗┛┗┫ ┗┛┗┗┻┗┗┻┛
|
|
# ┛
|
|
|
|
# Update the message:
|
|
auth_token = await current_app.core_auth_token_controller.get_token_from_key(
|
|
mongo_data_conn=current_app.data_mongo,
|
|
token_key=inbound_data.tokenKey
|
|
)
|
|
print("AUTH TOKEN RES:", auth_token)
|
|
|
|
success = False if auth_token is None else True
|
|
|
|
# ┳┓
|
|
# ┣┫┏┓┏┏┓┏┓┏┓┏┏┓
|
|
# ┛┗┗ ┛┣┛┗┛┛┗┛┗
|
|
# ┛
|
|
|
|
# Done here:
|
|
return ResponseModel(
|
|
status_code = StatusCodes.OK if success else StatusCodes.FAILED,
|
|
http_code = HttpCodes.SUCCESS if success else HttpCodes.INTERNAL_SERVER_ERROR,
|
|
data = auth_token.to_json() if success else auth_token
|
|
)
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** MAIN PROGRAM ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
pass
|