Package: tokko-auth
Install# Install from PyPipipinstalltokko-auth# Install from sources# Tokko REPO Permission is requiredpipinstall-egit@github.com:TokkoLabs/authorization.gitImport & Configure dj-pluginyour-project/settings.py# Add app to installed appsINSTALLED_APPS=['tokko_auth']# Also declare app's middlewareMIDDLEWARE=[# Has request JWT?"tokko_auth.middleware.HasJWTMiddleware",# JWT has required NAMESPACE?"tokko_auth.middleware.NamespaceAuthorizationMiddleware",# Fill "request.user" attribute"tokko_auth.middleware.UserRecoverMiddleware",]# Finally, declare your AUTH0_DOMAINAUTH0_DOMAIN='my-auth-sub-dns.auth0.com'Tools (Future)future.tools.permissionUsersRetrieve user permissionsfromtokko_auth.future.tools.permissionsimportPermissionProvider# Provider Initializationprovider=PermissionProvider()# Retrieve user permissionprovider.users.get("user@email.com")Response:{
    "user_id": "user@email.com",
    "permissions": [
        "namespace_a:action_1",
        "namespace_b:action_1",
        "namespace_a:action_2"
    ]
}Grant user permissionfromtokko_auth.future.tools.permissionsimportPermissionProvider# Provider Initializationprovider=PermissionProvider()# Grant permissionprovider.users.grant("user@email.com","namespace-is-required","action-is-required")Response:{
  "success": true
}Revoke user permissionfromtokko_auth.future.tools.permissionsimportPermissionProvider# Provider Initializationprovider=PermissionProvider()# Grant permissionprovider.users.revoke("user@email.com","namespace-is-required","action-is-required")Response:{
  "success": true
}PermissionsList permissionfromtokko_auth.future.tools.permissionsimportPermissionProvider# Provider Initializationprovider=PermissionProvider()# Create permissionprovider.permissions.list()# List permissions method also allows filter permissions# by namespace or action partial# provider.permissions.list(partial="nam")# provider.permissions.list(partial="act")Response:[{
    "namespace": "namespace",
    "action": "action",
    "permission": "namespace:action",
    "description": "description"
}]Create permissionfromtokko_auth.future.tools.permissionsimportPermissionProvider# Provider Initializationprovider=PermissionProvider()# Create permissionprovider.permissions.add("namespace-is-required","action-is-required","description-argument-is-optional")Response:{
    "namespace": "namespace-is-required",
    "action": "action-is-required",
    "permission": "namespace-is-required:action-is-required",
    "description": "description-argument-is-optional"
}Delete permissionfromtokko_auth.future.tools.permissionsimportPermissionProvider# Provider Initializationprovider=PermissionProvider()# Delete permissionprovider.permissions.delete("namespace-is-required","action-is-required")Response:{
  "success": true
}TestingLocal environmentUnit Testpython manage.py test authorization.tests.unitService Testpython manage.py test authorization.tests.serviceDocker environmentUnit Test# Require: docker-compose up [-d] [--build]
docker-compose exec app bash -c "python manage.py test authorization.tests.unit"Service Test# Require: docker-compose up [-d] [--build]
docker-compose exec app bash -c "python manage.py test authorization.tests.service"