-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
35 lines (24 loc) · 934 Bytes
/
main.py
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
from fastapi import FastAPI, Response, status, responses
app = FastAPI()
@app.get("/health")
async def root():
return {"alive": "true"}
@app.post("/authorize")
def authorize(body: dict, response: Response):
if body["resource"] == "kratos:admin":
return resolve_kratos_admin(body, response)
response.status_code = status.HTTP_403_FORBIDDEN
return {"status": "not authorized"}
def resolve_kratos_admin(body, response):
subject = body["subject"]["identity"]
if (
subject["traits"]["email"].split("@")[1] == "kern.ai"
and subject["verifiable_addresses"][0]["verified"]
):
response.status_code = status.HTTP_200_OK
return {"status": "authorized"}
response.status_code = status.HTTP_403_FORBIDDEN
return {"status": "not authorized"}
@app.get("/healthcheck")
def healthcheck() -> responses.PlainTextResponse:
return responses.PlainTextResponse("OK")