👮 Role-Based-Access-Control module for Orwynn framework
Gives controls to roles and their permissions in your backend application.
Installation
Via Poetry:
poetry add orwynn_rbac
Usage
Define default roles in your application:
DefaultRoles = [
DefaultRole(
name="sergeant",
title="Sergeant",
description="Flexible policeman",
permission_names=set(
"yourcompany.yourproject.citizen.permission.citizen:get",
"yourcompany.yourproject.tax.permission.tax:create",
"yourcompany.yourproject.pursue.permission.start:do"
)
),
...
]
NOTE: Default roles are initialized only once per fresh database.
In your Boot setup, initialize a RBACBoot class and get a bootscript from it:
from orwynn_rbac import RBACBoot
Boot(
...,
bootscripts=[
...,
RBACBoot(
default_roles=DefaultRoles
).get_bootscript()
]
)
In any module, where RBAC functionality is required (e.g. user access
checkers), import orwynn_rbac.module:
import orwynn_rbac
your_module = Module(
...,
imports=[
...,
orwynn_rbac.module
]
)
Checking access
To check an access to your controller you are free to implement own middleware,
retrieve an user id, e.g. from HTTP authorization header, and pass it to our
AccessService.check_user() method. A minimal middleware might look like this:
class AccessMiddleware(HttpMiddleware):
def __init__(
self,
covered_routes: list[str],
service: AccessService,
) -> None:
super().__init__(covered_routes)
self.service: AccessService = service
async def process(
self,
request: HttpRequest,
call_next: Callable,
) -> HttpResponse:
user_id: str | None = request.headers.get("user-id", None)
self.service.check_user(
user_id, str(request.url.components.path), request.method
)
response: HttpResponse = await call_next(request)
return response
The method AccessService.check_user() will raise a ForbiddenError if an
user with given id has no access to the route and method, so you just need to
call it with these arguments.
Metadata
Release files for orwynn-rbac 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| orwynn_rbac-0.1.4.tar.gz | 17.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| orwynn_rbac-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 39.2 kB
Release files / orwynn_rbac-0.1.4.tar.gz
| Download URL | orwynn_rbac-0.1.4.tar.gz |
|---|---|
| Size | 17.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cee9cfced2adac4fd0c9d83409a77e7b40b3039a35c567a7d2a845918fc4147b
|
|
BLAKE2b-256 checksum How to use checksums |
038abc1ee03d26ea405f821e02061d3ab9cd5bc8b865e1d8b0fc898732c4a687
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.11.6 Linux/6.6.3-zen1-1-zen
|
Release files / orwynn_rbac-0.1.4-py3-none-any.whl
| Download URL | orwynn_rbac-0.1.4-py3-none-any.whl |
|---|---|
| Size | 21.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e04f43288eda2f53738c94c56a52ba783caa361007f4f1587efd8d2eb78736dd
|
|
BLAKE2b-256 checksum How to use checksums |
a19aca0aaea50fe8472925c73bbaeb5c2a46f5c6c4191cb1f2f06580332ef5d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.11.6 Linux/6.6.3-zen1-1-zen
|