FastAPI - Authentication and Security
Identify the error in this FastAPI protected route code:
from fastapi import FastAPI, Depends, HTTPException
from fastapi.security import OAuth2PasswordBearer
app = FastAPI()
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
def get_current_user(token: str):
if token != "secret":
raise HTTPException(status_code=401, detail="Unauthorized")
return {"user": "admin"}
@app.get("/dashboard")
async def dashboard(user: dict = Depends(get_current_user)):
return user