django-tastypie-oauth
=====================
[](https://travis-ci.org/orcasgit/django-tastypie-oauth) [](https://coveralls.io/r/orcasgit/django-tastypie-oauth?branch=master) [](https://requires.io/github/orcasgit/django-tastypie-oauth/requirements/?branch=master)
Providing OAuth services for Tastypie APIs
Dependencies
============
This library works with two different OAuth providers, you must install one of them:
- django-oauth-toolkit: https://github.com/evonove/django-oauth-toolkit
- django-oauth2-provider: https://github.com/caffeinehit/django-oauth2-provider
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:
```python
# 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:
```python
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")
)
```
```python
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)
)
```
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.
=====================
[](https://travis-ci.org/orcasgit/django-tastypie-oauth) [](https://coveralls.io/r/orcasgit/django-tastypie-oauth?branch=master) [](https://requires.io/github/orcasgit/django-tastypie-oauth/requirements/?branch=master)
Providing OAuth services for Tastypie APIs
Dependencies
============
This library works with two different OAuth providers, you must install one of them:
- django-oauth-toolkit: https://github.com/evonove/django-oauth-toolkit
- django-oauth2-provider: https://github.com/caffeinehit/django-oauth2-provider
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:
```python
# 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:
```python
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")
)
```
```python
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)
)
```
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.
Metadata
Release files for django-tastypie-oauth 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-tastypie-oauth-0.0.3.tar.gz | 9.5 kB | Details |
Release files / django-tastypie-oauth-0.0.3.tar.gz
| Download URL | django-tastypie-oauth-0.0.3.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7b619486d406cb3f7db7ef13f6c38731415100d46f57d05f580a895d6c44838
|
|
BLAKE2b-256 checksum How to use checksums |
5ab55331bf3380d7f111390bf55c8da61f4031cd3f1f92291ce6ad2bf5b6fb1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |