require_scopes¶
require_scopes(*scopes, require_all=True) — builds a guard that requires AuthUser.scopes to cover the given OAuth scopes.
Signature¶
Semantics¶
OAuth scopes are AND by default: the user must possess every listed scope.
require_all |
Meaning |
|---|---|
True (default) |
user has all of scopes (AND) |
False |
user has at least one of scopes (OR) |
Examples¶
@use_guards(require_scopes("items.read")) # must have items.read
@use_guards(require_scopes("items.read", "items.write")) # both (default AND)
@use_guards(require_scopes("manage", "audit", require_all=False)) # either
Where scopes come from¶
Guards populate AuthUser.scopes from the credential:
jwt_bearer— thescopeclaim (space-separated string or list).oauth2_introspection— thescopefield of the introspection response.session_cookie—session.data["scopes"]via the defaultuser_builder.bearer_token/api_key— whatever yourverifyreturns.
Behaviour¶
- No
AuthUseron state →UnauthorizedError(401). - User present but scopes don't satisfy →
ForbiddenError(403).
Related¶
- require_authenticated — just needs a user.
- require_roles — gate by named roles.