diff options
author | Botond Hende <nettingman@gmail.com> | 2024-08-25 15:48:55 +0200 |
---|---|---|
committer | Botond Hende <nettingman@gmail.com> | 2024-08-25 15:48:55 +0200 |
commit | b0cab01ab962e4a0f704012eac28786597726be1 (patch) | |
tree | 1626da4b2a217267b2e35619c7ac21f11d4c50a2 /__main__.py | |
parent | ea2da15f2b04e3b4febf2230d4fbb0e2d6147dfc (diff) |
fastapi authentication wip
Diffstat (limited to '__main__.py')
-rw-r--r-- | __main__.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/__main__.py b/__main__.py index 16b0f63..deacefa 100644 --- a/__main__.py +++ b/__main__.py @@ -1,15 +1,22 @@ -import os.path -from fastapi import FastAPI -from .datatemplates.agent_id import AgentId -from .modules import daemon -from .config import Config +from typing import Annotated + +from fastapi import FastAPI, Depends, Request +from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm app = FastAPI() +oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") + + +@app.post("/token") +async def login(form_data: OAuth2PasswordRequestForm = Depends()): + user = form_data.username + return {"access_token": user, "token_type": "bearer"} + -@app.post("/tasks") -async def get_tasks(agent_id: AgentId): - return "foo" +@app.get("/{callsign}/tasks") +async def get_tasks(callsign: str, token: Annotated[str, Depends(oauth2_scheme)]): + return f'{{"callsign": "{callsign}", "token": "{token}"}}' # if __name__ == "__main__": # with open(os.path.join(os.path.dirname(__file__), Config.TOKEN_FILE_NAME)) as f: |