Spaces:
Sleeping
Sleeping
Update components/middleware.py
Browse files- components/middleware.py +8 -69
components/middleware.py
CHANGED
|
@@ -25,75 +25,15 @@ import time
|
|
| 25 |
#from geopy.exc import GeocoderServiceError
|
| 26 |
#geolocator = Nominatim(user_agent="velocity")
|
| 27 |
|
| 28 |
-
from mongodbconnection import provideClient
|
| 29 |
-
|
| 30 |
-
from privy import PrivyAPI
|
| 31 |
-
|
| 32 |
-
client = PrivyAPI(
|
| 33 |
-
app_id="cmihenof71gd2l40c4ieyu21h",
|
| 34 |
-
app_secret="4njjG89h1PztoHH98z9ghLaswTLmE7qb7RrEx2t9ZyvavtrYfYSsfc15cKjzEvkhE2iv6tGqmR1PA2WXT9ALHArV"
|
| 35 |
-
)
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
mongoclient=provideClient()
|
| 39 |
-
db=client["mcp_db"]
|
| 40 |
-
coll=db["mcp_col"]
|
| 41 |
-
|
| 42 |
|
|
|
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
-
'''
|
| 48 |
-
def GEOCODER(coords):
|
| 49 |
-
try:
|
| 50 |
-
lat = coords.get("latitude")
|
| 51 |
-
lon = coords.get("longitude")
|
| 52 |
-
|
| 53 |
-
if lat is None or lon is None:
|
| 54 |
-
return {
|
| 55 |
-
"status": "error",
|
| 56 |
-
"message": "Missing latitude or longitude.",
|
| 57 |
-
"data": None
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
location = geolocator.reverse(f"{lat}, {lon}", exactly_one=True)
|
| 61 |
-
|
| 62 |
-
if location and "address" in location.raw:
|
| 63 |
-
country_name = location.raw["address"].get("country")
|
| 64 |
-
country_code = location.raw["address"].get("country_code")
|
| 65 |
-
|
| 66 |
-
return {
|
| 67 |
-
"status": "success",
|
| 68 |
-
"message": "Location resolved successfully.",
|
| 69 |
-
"data": {
|
| 70 |
-
"country": country_name,
|
| 71 |
-
"code": country_code.upper() if country_code else None
|
| 72 |
-
}
|
| 73 |
-
}
|
| 74 |
|
| 75 |
-
return {
|
| 76 |
-
"status": "not_found",
|
| 77 |
-
"message": "Location could not be resolved.",
|
| 78 |
-
"data": None
|
| 79 |
-
}
|
| 80 |
|
| 81 |
-
except GeocoderServiceError as e:
|
| 82 |
-
return {
|
| 83 |
-
"status": "error",
|
| 84 |
-
"message": f"Geocoding service error: {str(e)}",
|
| 85 |
-
"data": None
|
| 86 |
-
}
|
| 87 |
|
| 88 |
-
except Exception as e:
|
| 89 |
-
return {
|
| 90 |
-
"status": "error",
|
| 91 |
-
"message": f"Unexpected error: {str(e)}",
|
| 92 |
-
"data": None
|
| 93 |
-
}
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
'''
|
| 97 |
|
| 98 |
def SignatureVerification(X_401_Addr,X_401_Nonce,X_401_Sign,challange):
|
| 99 |
|
|
@@ -265,24 +205,21 @@ class x401Kit(BaseHTTPMiddleware):
|
|
| 265 |
|
| 266 |
NONCE=SecretNonceGenerator()
|
| 267 |
aud=request.headers.get("origin")
|
| 268 |
-
MPC_=request.headers.get("mpc")
|
| 269 |
-
MPC_ID=request.headers.get("mpc_id")
|
| 270 |
-
MPC_STATUS=request.headers.get("mpc_status")
|
| 271 |
X_401_Nonce=request.headers.get("X-401-Nonce")
|
| 272 |
X_401_Sign=request.headers.get("X-401-Signature")
|
| 273 |
X_401_Addr=request.headers.get("X-401-Addr")
|
| 274 |
client_jwt=request.headers.get("x-jwt")
|
|
|
|
| 275 |
|
| 276 |
|
| 277 |
|
|
|
|
| 278 |
|
|
|
|
| 279 |
|
| 280 |
-
|
| 281 |
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
REQUIRED_SERVICE=None
|
| 286 |
|
| 287 |
|
| 288 |
if client_jwt:
|
|
@@ -300,6 +237,8 @@ class x401Kit(BaseHTTPMiddleware):
|
|
| 300 |
|
| 301 |
if not X_401_Addr and not X_401_Nonce and not X_401_Sign :
|
| 302 |
|
|
|
|
|
|
|
| 303 |
payload401={
|
| 304 |
|
| 305 |
"X-401-Status":"Authrequired",
|
|
|
|
| 25 |
#from geopy.exc import GeocoderServiceError
|
| 26 |
#geolocator = Nominatim(user_agent="velocity")
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
from mongodbconnection import provideClient
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
def SignatureVerification(X_401_Addr,X_401_Nonce,X_401_Sign,challange):
|
| 39 |
|
|
|
|
| 205 |
|
| 206 |
NONCE=SecretNonceGenerator()
|
| 207 |
aud=request.headers.get("origin")
|
|
|
|
|
|
|
|
|
|
| 208 |
X_401_Nonce=request.headers.get("X-401-Nonce")
|
| 209 |
X_401_Sign=request.headers.get("X-401-Signature")
|
| 210 |
X_401_Addr=request.headers.get("X-401-Addr")
|
| 211 |
client_jwt=request.headers.get("x-jwt")
|
| 212 |
+
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
+
|
| 217 |
|
| 218 |
+
REQUIRED_SERVICE=None
|
| 219 |
|
|
|
|
| 220 |
|
| 221 |
+
|
| 222 |
+
|
|
|
|
|
|
|
| 223 |
|
| 224 |
|
| 225 |
if client_jwt:
|
|
|
|
| 237 |
|
| 238 |
if not X_401_Addr and not X_401_Nonce and not X_401_Sign :
|
| 239 |
|
| 240 |
+
|
| 241 |
+
|
| 242 |
payload401={
|
| 243 |
|
| 244 |
"X-401-Status":"Authrequired",
|