blob: deacefaf4d38b73bb5c86e16b81877b619d13686 (
plain)
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
|
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.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:
# token = f.read().strip()
#
# d = daemon.Daemon(Config.AGENT_SYMBOL, token)
# d.run()
|