Browse Source

http api to just check authentication status

this will be useful for #7
boyska 1 year ago
parent
commit
0d31b32429
1 changed files with 7 additions and 0 deletions
  1. 7 0
      pizzicore/pizzicore.py

+ 7 - 0
pizzicore/pizzicore.py

@@ -119,6 +119,9 @@ security = HTTPBasic()
 class CountersDescription(BaseModel):
     counters: int
 
+class UserDescription(BaseModel):
+    role: str
+
 
 class Value(BaseModel):
     counter: int
@@ -136,6 +139,10 @@ def get_current_role(credentials: HTTPBasicCredentials = Depends(security)):
         )
     return "admin"
 
+@app.get("/v1/whoami/")
+async def whoami(role: str = Depends(get_current_role)):
+    return UserDescription(role=role)
+
 @app.get("/v1/counter/")
 async def get_counter_number():
     return CountersDescription(counters=len(counter_store.values))