Skip to content

honestbleeps/django-tastypie-oauth

 
 

Repository files navigation

django-tastypie-oauth

Build Status Coverage Status Requirements Status

Providing OAuth services for Tastypie APIs

Dependencies

This library works with two different OAuth providers, you must install one of them:

Set up one of these libraries before continuing

Usage

  1. Add tastypie_oauth to INSTALLED_APPS in Django.

  2. 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.

  3. 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()
  4. 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.

About

Providing OAuth services for Tastypie APIs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%