A Django app extension of django-oauth-toolkit that implements scope based applications.
Project description
Mad Oauth2
Mad Oauth2 app is an extension of django-oauth-toolkit that implements scopes and schemes in detail
Quick start
-
Add "mad_oauth2" 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", }
-
Run
python manage.py migrate
to create mad_oauth2 models.
Important Note
First add scopes and throttles from the admin, then mark the view with the respective scope. Changes will take effect once the code is deployed(redeployed/rebuild).
Clearing Expired Tokens
Run celery periodic task to clear expired tokens
mad_oauth2.tasks.removeExpiredTokens
Restricting Views with Scopes
this_view = "user"
throttle_scope = this_view
required_alternate_scopes = mad_oauth2.utils.requiredScopesForView(this_view)
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file mad_oauth2-3.0.1.tar.gz
.
File metadata
- Download URL: mad_oauth2-3.0.1.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14ef28d4241c51ad344368ba202b3d574c7f7e9b335020c662c22e092e172dee |
|
MD5 | 0e75ef646e6bcea48b5382833af6b893 |
|
BLAKE2b-256 | d26a051247855148bed2db60258778a1f78b403d0b7edd4d35f15d056119571a |