Skip to main content

Tokko Auth2 flavor.

Project description

Install

# Install from PyPi
pip install tokko-auth
# Install from sources
# Tokko REPO Permission is required
pip install -e git@github.com:TokkoLabs/authorization.git

Import & Configure dj-plugin

your-project/settings.py

# Add app to installed apps
INSTALLED_APPS = [
    'tokko_auth'
]

# Also declare app's middleware
MIDDLEWARE = [
    # 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_DOMAIN
AUTH0_DOMAIN = 'my-auth-sub-dns.auth0.com'

Tools (Future)

future.tools.permission

Users

Retrieve user permissions

from tokko_auth.future.tools.permissions import PermissionProvider

# Provider Initialization
provider = PermissionProvider()
# Retrieve user permission
provider.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 permission

from tokko_auth.future.tools.permissions import PermissionProvider

# Provider Initialization
provider = PermissionProvider()
# Grant permission
provider.users.grant("user@email.com", "namespace-is-required", "action-is-required")

Response:

{
  "success": true
}

Revoke user permission

from tokko_auth.future.tools.permissions import PermissionProvider

# Provider Initialization
provider = PermissionProvider()
# Grant permission
provider.users.revoke("user@email.com", "namespace-is-required", "action-is-required")

Response:

{
  "success": true
}

Permissions

List permission

from tokko_auth.future.tools.permissions import PermissionProvider

# Provider Initialization
provider = PermissionProvider()
# Create permission
provider.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 permission

from tokko_auth.future.tools.permissions import PermissionProvider

# Provider Initialization
provider = PermissionProvider()
# Create permission
provider.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 permission

from tokko_auth.future.tools.permissions import PermissionProvider

# Provider Initialization
provider = PermissionProvider()
# Delete permission
provider.permissions.delete("namespace-is-required", "action-is-required")

Response:

{
  "success": true
}

Testing

Local environment

Unit Test

python manage.py test authorization.tests.unit

Service Test

python manage.py test authorization.tests.service

Docker environment

Unit 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"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

tokko_auth-0.2.2-py3-none-any.whl (39.3 kB view details)

Uploaded Python 3

File details

Details for the file tokko_auth-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: tokko_auth-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 39.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.6

File hashes

Hashes for tokko_auth-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 191f4e0f0b2f12280992034a4ef560d55ec87d09f9f48d8ad96e295c2189695f
MD5 ec9e4c8b40fd9b8303e0622e2ad9a311
BLAKE2b-256 5352e953616b288396ee43b74f9437402053e8f3d0752c4ed288bb3e0962ef63

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page