Quart integration#
Install#
pip install py-oidc-auth[quart]
Minimal application#
from quart import Quart
from py_oidc_auth import QuartOIDCAuth
app = Quart(__name__)
auth = QuartOIDCAuth(
client_id="my client",
client_secret="secret",
discovery_url="https://idp.example.org/realms/demo/.well-known/openid-configuration",
scopes="openid profile email",
)
app.register_blueprint(auth.create_auth_blueprint(prefix=""))
Protecting routes#
Quart route functions are async. The wrapped view receives the validated token as its first positional argument.
@app.get("/me")
@auth.required()
async def me(token):
return {"sub": token.sub}
@app.get("/maybe_me")
@auth.optional()
async def maybe_me(token):
if token is None:
return {"anonymous": True}
return {"sub": token.sub}