Spaces:
Sleeping
Sleeping
File size: 1,437 Bytes
40917a8 eafcdaf 8dbfee6 40917a8 eafcdaf 40917a8 98765b7 40917a8 98765b7 40917a8 8dbfee6 40917a8 06b9102 40917a8 8dbfee6 eafcdaf d050638 eafcdaf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
from fastapi import FastAPI,Request,HTTPException,Response
from pydantic import BaseModel
from fastapi.responses import JSONResponse
import uuid
from fastapi.middleware.cors import CORSMiddleware
import json
import base64
from components.middleware import x401Kit
from components.mongodbconnection import provideClient
import hashlib
import secrets
app=FastAPI()
dbclient=provideClient()
db=dbclient["sdklogs_db"]
col=db["sdklogs_col"]
origins=["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.add_middleware(
x401Kit,
protected_paths=[
"/x401_auth"
]
)
def generate_sha256_hex_challenge():
random_data = secrets.token_bytes(32)
challenge = hashlib.sha256(random_data).hexdigest()
return challenge
@app.get("/x401_auth")
def Auth401(request:Request):
return {"token":""}
@app.get("/x401_web_auth_challange")
def WebAuthChallange(request:Request):
challange=generate_sha256_hex_challenge()
return {"challange":challange}
@app.get("/sdklogs/{id}")
def SDKLog(id):
document=col.find_one({"owner":"system"})
details=None
if document:
logs=document["logs"]
for data in logs:
if data.signer==id:
details=data
return JSONResponse(content={"details":details})
|