Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
django-tastypie-oauth
Advanced tools
Providing OAuth services for Tastypie APIs
This library works with two different OAuth providers, you must install one of them:
Set up one of these libraries before continuing
Add tastypie_oauth
to INSTALLED_APPS
in Django.
Specify OAUTH_ACCESS_TOKEN_MODEL
in the Django settings. At this time it can be 'oauth2_provider.models.AccessToken'
for django-oauth-toolkit and 'provider.oauth2.models.AccessToken'
for django-oauth2-provider.
When you create your Tastypie resources, use OAuth20Authentication
like so:
# mysite/polls/api.py
from tastypie.resources import ModelResource
from tastypie.authorization import DjangoAuthorization
from polls.models import Poll, Choice
from tastypie import fields
from tastypie_oauth.authentication import OAuth20Authentication
class ChoiceResource(ModelResource):
class Meta:
queryset = Choice.objects.all()
resource_name = 'choice'
authorization = DjangoAuthorization()
authentication = OAuth20Authentication()
class PollResource(ModelResource):
choices = fields.ToManyField(ChoiceResource, 'choice_set', full=True)
class Meta:
queryset = Poll.objects.all()
resource_name = 'poll'
authorization = DjangoAuthorization()
authentication = OAuth20Authentication()
Or, if you want to use scoped authentication, use the OAuth2ScopedAuthentication
class:
from tastypie_oauth.authentication import OAuth20ScopedAuthentication
# With Django-oauth-toolkit
class ChoiceResource(ModelResource):
poll = fields.ToOneField("polls.api.PollResource", "poll", full=False)
class Meta:
resource_name = 'choice'
queryset = Choice.objects.all()
authorization = DjangoAuthorization()
authentication = OAuth2ScopedAuthentication(
post=("read write",),
get=("read",),
put=("read","write")
)
from provider.constants import READ, WRITE, READ_WRITE
from tastypie_oauth.authentication import OAuth20ScopedAuthentication
# With Django-oauth2-provider
class ChoiceResource(ModelResource):
poll = fields.ToOneField("polls.api.PollResource", "poll", full=False)
class Meta:
resource_name = 'choice'
queryset = Choice.objects.all()
authorization = DjangoAuthorization()
authentication = OAuth2ScopedAuthentication(
post=(READ_WRITE,),
get=(READ,),
put=(READ,WRITE)
)
After authorizing the user and gaining an access token, you can use the API almost as before with just one minor change. You must add a oauth_consumer_key
GET or POST parameter with the access token as the value, or put the access token in "Authorization" header.
FAQs
Providing OAuth services for Tastypie APIs
We found that django-tastypie-oauth demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.