This page assumes a frontend that already signs people in with a Scute SDK and sends the access token to your API.
Install
pip install "scute[fastapi] @ git+https://github.com/scuteai/scute-python" uvicornSet the credentials
export SCUTE_APP_ID=app_xxxexport SCUTE_SECRET=...SCUTE_SECRET is only needed for the permission check in step 4.
Verify the token
main.pypythonfrom typing import Annotatedfrom fastapi import Depends, FastAPIfrom scute import Scute, Sessionfrom scute.contrib.fastapi import ScuteAuthapp = FastAPI()auth = ScuteAuth(Scute())@app.get("/me")def me(session: Annotated[Session, Depends(auth.session)]) -> dict: return {"user_id": session.user_id, "impersonated": session.impersonated}auth.session reads the token from the X-Authorization header, then Authorization: Bearer, then the browser SDK's sc-access-token__<app id> cookie. It verifies the token against the app's published keys and returns a Session. A missing or invalid token gets 401 with {"detail": {"error": "...", "reason": "expired"}}.
Check a permission
main.pypython@app.post("/invoices/{id}/refund", dependencies=[Depends(auth.require("refund", "invoice:{id}"))])def refund(id: str) -> dict: return {"refunded": id}auth.require verifies the session, fills {id} from the path and asks Scute whether the user may refund invoice:42. Anything other than a plain allow gets 403.
Run it
uvicorn main:appcurl localhost:8000/me -H "X-Authorization: $ACCESS_TOKEN"
Without the framework helper#
from scute import InvalidToken, Scutescute = Scute()try: session = scute.tokens.verify(token)except InvalidToken as e: print(e.reason) # "missing", "malformed", "expired", "wrong_app", ...See Verify tokens for every check and failure reason, and FastAPI for the full integration.