Moved the scope module one level up into provider
Replaced the write scope with a new write scope that includes reading Added helper function to turn a scope integer back into a list of names Access token response now returns a space seperated list of scope names Default access token scope is now the first defined scope in constants Version bump
This commit is contained in:
parent
eb65a4f648
commit
a9fd2a7ca2
|
@ -1,7 +0,0 @@
|
|||
# django-oauth2-provider
|
||||
|
||||
![](https://secure.travis-ci.org/caffeinehit/django-oauth2-provider.png)
|
||||
|
||||
*django-oauth2-provider* is a Django application that provides customizable OAuth2_ authentication for your Django projects.
|
||||
|
||||
[Documentation](http://readthedocs.org/docs/django-oauth2-provider/en/latest/)
|
|
@ -7,3 +7,11 @@ django-oauth2-provider
|
|||
customizable OAuth2\_ authentication for your Django projects.
|
||||
|
||||
`Documentation <http://readthedocs.org/docs/django-oauth2-provider/en/latest/>`_
|
||||
|
||||
Changes
|
||||
=======
|
||||
|
||||
.. toctree:
|
||||
:maxdepth 4:
|
||||
|
||||
docs/changes
|
19
docs/api.rst
19
docs/api.rst
|
@ -60,6 +60,13 @@
|
|||
:members:
|
||||
:no-undoc-members:
|
||||
|
||||
`provider.scope`
|
||||
-----------------------
|
||||
.. automodule:: provider.scope
|
||||
:members:
|
||||
:no-undoc-members:
|
||||
|
||||
|
||||
`provider.utils`
|
||||
----------------
|
||||
.. automodule:: provider.utils
|
||||
|
@ -75,12 +82,6 @@
|
|||
`provider.oauth2`
|
||||
=================
|
||||
|
||||
`provider.oauth2.auth`
|
||||
----------------------
|
||||
.. automodule:: provider.oauth2.auth
|
||||
:members:
|
||||
:no-undoc-members:
|
||||
|
||||
`provider.oauth2.forms`
|
||||
-----------------------
|
||||
.. automodule:: provider.oauth2.forms
|
||||
|
@ -93,12 +94,6 @@
|
|||
:members:
|
||||
:no-undoc-members:
|
||||
|
||||
`provider.oauth2.scope`
|
||||
-----------------------
|
||||
.. automodule:: provider.oauth2.scope
|
||||
:members:
|
||||
:no-undoc-members:
|
||||
|
||||
`provider.oauth2.urls`
|
||||
----------------------
|
||||
.. automodule:: provider.oauth2.urls
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
v 0.2
|
||||
-----
|
||||
* *Breaking change* Moved ``provider.oauth2.scope`` to ``provider.scope``
|
||||
* *Breaking change* Replaced the write scope with a new write scope that includes reading
|
||||
* Default scope for new ``provider.oauth2.models.AccessToken`` is now ``provider.constants.SCOPES[0][0]``
|
||||
* Access token response returns a space seperated list of scopes instead of an integer value
|
|
@ -52,6 +52,14 @@ API
|
|||
:maxdepth: 4
|
||||
|
||||
api
|
||||
|
||||
Changes
|
||||
#######
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 3
|
||||
|
||||
changes
|
||||
|
||||
|
||||
Made by `Caffeinehit <http://www.caffeinehit.com/>`_.
|
||||
|
|
|
@ -1 +1 @@
|
|||
__version__ = "0.1.8"
|
||||
__version__ = "0.2.0"
|
||||
|
|
|
@ -13,10 +13,11 @@ RESPONSE_TYPE_CHOICES = getattr(settings, 'OAUTH_RESPONSE_TYPE_CHOICES', ("code"
|
|||
|
||||
READ = 1 << 1
|
||||
WRITE = 1 << 2
|
||||
READ_WRITE = READ | WRITE
|
||||
|
||||
DEFAULT_SCOPES = (
|
||||
(READ, 'read'),
|
||||
(WRITE, 'write'),
|
||||
(READ_WRITE, 'write'),
|
||||
)
|
||||
|
||||
SCOPES = getattr(settings, 'OAUTH_SCOPES', DEFAULT_SCOPES)
|
||||
|
|
|
@ -6,9 +6,9 @@ from django.utils.translation import ugettext as _
|
|||
from provider import constants
|
||||
from provider.constants import RESPONSE_TYPE_CHOICES, SCOPES
|
||||
from provider.forms import OAuthForm, OAuthValidationError
|
||||
from provider.oauth2 import scope
|
||||
from provider import scope
|
||||
from provider.oauth2.models import Client, Grant, RefreshToken
|
||||
from provider.oauth2.scope import SCOPE_NAMES, SCOPE_NAME_DICT
|
||||
from provider.scope import SCOPE_NAMES, SCOPE_NAME_DICT
|
||||
|
||||
class ClientForm(forms.ModelForm):
|
||||
"""
|
||||
|
|
|
@ -7,6 +7,7 @@ these models with fields and and methods to be compatible with the views in
|
|||
from datetime import datetime
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
from provider import constants
|
||||
from provider.constants import CLIENT_TYPES, SCOPES
|
||||
from provider.oauth2.managers import AccessTokenManager
|
||||
from provider.utils import short_token, long_token, get_token_expiry, \
|
||||
|
@ -90,7 +91,7 @@ class AccessToken(models.Model):
|
|||
token = models.CharField(max_length=255, default=short_token)
|
||||
client = models.ForeignKey(Client)
|
||||
expires = models.DateTimeField(default=get_token_expiry)
|
||||
scope = models.IntegerField(default=0)
|
||||
scope = models.IntegerField(default=constants.SCOPES[0][0])
|
||||
|
||||
objects = AccessTokenManager()
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
from django.contrib.auth.models import User
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test import TestCase
|
||||
from provider.constants import CLIENT_TYPES
|
||||
from provider import constants
|
||||
from provider import scope
|
||||
from provider.oauth2.forms import ClientForm
|
||||
from provider.oauth2.models import Client, Grant
|
||||
from provider.testcases import AuthorizationTest, AccessTokenTest, \
|
||||
|
@ -45,8 +46,23 @@ class TestClientForm(TestCase, Mixin):
|
|||
self.assertFalse(form.is_valid())
|
||||
|
||||
form = ClientForm({'name': 'TestName', 'url': 'http://127.0.0.1:8000',
|
||||
'redirect_uri': 'http://localhost:8000/', 'client_type': CLIENT_TYPES[0][0]})
|
||||
'redirect_uri': 'http://localhost:8000/', 'client_type': constants.CLIENT_TYPES[0][0]})
|
||||
self.assertTrue(form.is_valid())
|
||||
client = form.save()
|
||||
|
||||
class TestScopeNames(TestCase, Mixin):
|
||||
def setUp(self):
|
||||
self._scopes = constants.SCOPES
|
||||
constants.SCOPES = constants.DEFAULT_SCOPES
|
||||
def tearDown(self):
|
||||
constants.SCOPES = self._scopes
|
||||
|
||||
def test_get_scope_names(self):
|
||||
names = scope.names(constants.READ)
|
||||
self.assertEqual('read', ' '.join(names))
|
||||
|
||||
names = scope.names(constants.READ_WRITE)
|
||||
names.sort()
|
||||
|
||||
self.assertEqual('read write', ' '.join(names))
|
||||
|
||||
|
|
|
@ -61,3 +61,14 @@ def check(wants, has):
|
|||
if wants & has < wants:
|
||||
return False
|
||||
return True
|
||||
|
||||
def names(scope):
|
||||
"""
|
||||
Returns a list of scope names as defined in :attr:`provider.constants.SCOPES`
|
||||
for a given scope integer.
|
||||
"""
|
||||
return [
|
||||
name
|
||||
for (name, value) in SCOPE_NAME_DICT.iteritems()
|
||||
if check(value, scope)
|
||||
]
|
|
@ -6,6 +6,7 @@ from django.views.generic.base import TemplateView, View
|
|||
from provider import constants
|
||||
import json
|
||||
import urlparse
|
||||
from provider import scope
|
||||
|
||||
class OAuthError(Exception):
|
||||
"""
|
||||
|
@ -432,7 +433,7 @@ class AccessToken(OAuthView, Mixin):
|
|||
'access_token': access_token.token,
|
||||
'expires_in': access_token.get_expire_delta(),
|
||||
'refresh_token': access_token.refresh_token.token,
|
||||
'scope': access_token.scope
|
||||
'scope': ' '.join(scope.names(access_token.scope)),
|
||||
}), mimetype='application/json'
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue