Main Types¶
- class flask_principal.Permission(*needs)¶
Represents needs, any of which must be present to access a resource
Parameters: needs – The needs for this permission - allows(identity)¶
Whether the identity can access this permission.
Parameters: identity – The identity
- can()¶
Whether the required context for this permission has access
This creates an identity context and tests whether it can access this permission
- difference(other)¶
Create a new permission consisting of requirements in this permission and not in the other.
- issubset(other)¶
Whether this permission needs are a subset of another
Parameters: other – The other permission
- require(http_exception=None)¶
Create a principal for this permission.
The principal may be used as a context manager, or a decroator.
If http_exception is passed then abort() will be called with the HTTP exception code. Otherwise a PermissionDenied exception will be raised if the identity does not meet the requirements.
Parameters: http_exception – the HTTP exception code (403, 401 etc)
- reverse()¶
Returns reverse of current state (needs->excludes, excludes->needs)
- test(http_exception=None)¶
Checks if permission available and raises relevant exception if not. This is useful if you just want to check permission without wrapping everything in a require() block.
This is equivalent to:
with permission.require(): pass
- union(other)¶
Create a new permission with the requirements of the union of this and other.
Parameters: other – The other permission
- class flask_principal.Identity(id, auth_type=None)¶
Represent the user’s identity.
Parameters: - id – The user id
- auth_type – The authentication type used to confirm the user’s identity.
The identity is used to represent the user’s identity in the system. This object is created on login, or on the start of the request as loaded from the user’s session.
Once loaded it is sent using the identity-loaded signal, and should be populated with additional required information.
Needs that are provided by this identity should be added to the provides set after loading.
- can(permission)¶
Whether the identity has access to the permission.
Parameters: permission – The permission to test provision for.
- class flask_principal.AnonymousIdentity¶
An anonymous identity
- class flask_principal.IdentityContext(permission, http_exception=None)¶
The context of an identity for a permission.
Note
The principal is usually created by the flaskext.Permission.require method call for normal use-cases.
The principal behaves as either a context manager or a decorator. The permission is checked for provision in the identity, and if available the flow is continued (context manager) or the function is executed (decorator).
- can()¶
Whether the identity has access to the permission
- http_exception = None¶
The permission of this principal
- identity¶
The identity of this principal