Skip to main content

A Django app extension of django-oauth-toolkit that implements scope based applications.

Project description

Mad Oauth2

Mad Oauth2 app is an extention of django-oauth-toolkit that implements scopes and schemes in detail

Quick start

  1. Add "mad_oaut2" to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'oauth2_provider',
        'mad_oauth2',
        ...
    ]
    
    REST_FRAMEWORK = {
        ...
        "DEFAULT_PERMISSION_CLASSES": (
            "oauth2_provider.contrib.rest_framework.TokenMatchesOASRequirements",
            # OR
            "oauth2_provider.contrib.rest_framework.TokenHasResourceScope",
        ),
        'DEFAULT_THROTTLE_CLASSES': [
            'mad_oauth2.throttling.BaseScopedRateThrottle'
        ],
        ...
    }
    
    OAUTH2_PROVIDER_APPLICATION_MODEL="mad_oauth2.Application"
    OAUTH2_PROVIDER = {
        "SCOPES_BACKEND_CLASS": "mad_oauth2.oauth2.ApplicationScopes"
        "APPLICATION_ADMIN_CLASS": "mad_oauth2.admin.ApplicationAdminClass",
    }
    
  2. Run python manage.py migrate to create mad_oauth2 models.

Setting View

this_view = "user"
throttle_scope = this_view
required_alternate_scopes = {
    "GET": [[this_view+":read"]],
    "POST": [[this_view+":create"]],
    "PUT":  [[this_view+":update"]],
    "PATCH":  [[this_view+":update"]],
    "DELETE": [[this_view+":delete"]],
}

Clearing Expired Tokens

Run celery periodic task to clear expired tokens mad_oauth2.tasks.removeExpiredTokens

Restricting Views with Scopes

Visit the official documentation for django-oauth-toolkit for more details on this:

https://django-oauth-toolkit.readthedocs.io/en/latest/rest-framework/permissions.html

Throttling Requests

REST_FRAMEWORK = {
    ...
    'DEFAULT_THROTTLE_CLASSES': [
        'mad_oauth2.throttling.BaseScopedRateThrottle'
    ],
    ...
}

Visit the official documentation for djangorestframework for more details this:

https://www.django-rest-framework.org/api-guide/throttling/#scopedratethrottle

Project details


Download files

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

Source Distribution

mad_oauth2-0.3.3.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file mad_oauth2-0.3.3.tar.gz.

File metadata

  • Download URL: mad_oauth2-0.3.3.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for mad_oauth2-0.3.3.tar.gz
Algorithm Hash digest
SHA256 2a4e6262f3e3a54455dbf16404e3817b3f89109e8ad831f9f766f7ff16e45369
MD5 d5a23a3a1e1e3376f97f8f3147ec304a
BLAKE2b-256 a2b0b38f9fbdfd20dd2829b670d940b1a5820c5f03176ed8fb6a68138469f3f2

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