Git Product home page Git Product logo

django-tastypie-oauth's Introduction

django-tastypie-oauth

Build Status Coverage Status Requirements Status

Providing OAuth services for Tastypie APIs

Dependencies

This library works with the django-oauth-toolkit library. Make sure you have it set up before continuing.

Usage

  1. Add tastypie_oauth to INSTALLED_APPS in Django.

  2. 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
    
    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")
            )
  3. 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.

django-tastypie-oauth's People

Contributors

brad avatar grokcode avatar jannkleen avatar pablodiazgutierrez avatar requires avatar thisiscam avatar yeago avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.