Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI,Depends
|
| 2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
from openkitx403 import OpenKit403Middleware, require_openkitx403_user
|
| 4 |
+
app=FastAPI()
|
| 5 |
+
|
| 6 |
+
origins=[
|
| 7 |
+
"http://localhost:3000"
|
| 8 |
+
]
|
| 9 |
+
|
| 10 |
+
app.add_middleware(
|
| 11 |
+
CORSMiddleware,
|
| 12 |
+
allow_origins=origins,
|
| 13 |
+
allow_credentials=True,
|
| 14 |
+
allow_methods=["*"],
|
| 15 |
+
allow_headers=["*"],
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
app.add_middleware(
|
| 21 |
+
OpenKit403Middleware,
|
| 22 |
+
audience="http://127.0.0.1:8001",
|
| 23 |
+
issuer="my-api-v1",
|
| 24 |
+
ttl_seconds=60,
|
| 25 |
+
bind_method_path=True,
|
| 26 |
+
replay_backend="memory"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
@app.get("/protected")
|
| 36 |
+
async def protected(user = Depends(require_openkitx403_user)):
|
| 37 |
+
return {"message": "Hello!", "wallet": user.address}
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|