justapi — /docs

Extracting User from Token

from justapi import JustAPIApp, Security
from justapi.auth import OAuth2PasswordBearer

app = JustAPIApp()
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")

async def get_current_user(token: str = Security(oauth2_scheme)):
    # Decode JWT and return user
    user = decode_token(token)
    if user is None:
        raise HTTPException(status_code=401, detail="Invalid token")
    return user

@app.get("/users/me")
def read_me(current_user: dict = Security(get_current_user)):
    return current_user

See Also

JustAPI v2.0.9 — Open Source MIT License · Built with WebTUI · GitHub

NORMAL master justapi/docs
utf-8 Top 1:1