Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
1a66f68
create TokenHasResourceScope a drf permission class
drgarcia1986 Jul 7, 2015
7a9ee1b
force version 1.0.1 of mock library in testing requirements (because …
drgarcia1986 Jul 10, 2015
b81cbe4
Put additional information when generating token responses.
calvin Aug 17, 2015
b7078e8
updated changelog with new features
synasius Sep 17, 2015
2d896c1
updated contributors list
synasius Sep 17, 2015
68d03c0
Fixing doc about SessionAuthenticationMiddleware
lzen Sep 23, 2015
07df6f6
``server_class`` is now pluggable through Django settings
Gr1N Sep 27, 2015
55035a5
urlpatterns should be a plain list or `django.conf.urls.url` instances
dulacp Oct 15, 2015
d22958e
Add Django 1.9 to the test matrix
dulacp Oct 15, 2015
c1e83dd
Merge branch 'lzen-patch-1'
outsbart Oct 15, 2015
3c02de0
Merge branch 'extra-credentials' of https://github.com/calvin/django-…
outsbart Oct 15, 2015
6c7fdb2
Use the native NullHandler
dulacp Oct 15, 2015
f9f50b1
tested OAuthLibCoreBackend's _get_extra_credentials method overriding
outsbart Oct 15, 2015
a2b6cef
Use a plain list of url instances for the tests urls too
dulacp Oct 15, 2015
65f22bb
Fix the unittest import
dulacp Oct 15, 2015
a72e5bd
Ensure the MIDDLEWARE_CLASSES content is a tuple for concatenation
dulacp Oct 15, 2015
4ac449c
Implement a compatibility for the url templatetag
dulacp Oct 15, 2015
a573eee
Use a compat import for the NullHandler
dulacp Oct 15, 2015
489cf13
Drop support for the py3.3 under Django 1.9 but add support for py3.5
dulacp Oct 15, 2015
c2b9b5f
Extract the compat for the null handler since it causes an import loop
dulacp Oct 15, 2015
8043ffb
Flip the try/except import for the unittest module
dulacp Oct 15, 2015
24d70a0
Remove the python3.5 interpreter for now since Travis is not ready
dulacp Oct 15, 2015
89d6e3f
Use the new travis architecture for better stability
dulacp Oct 15, 2015
042ca54
Remove an unsupported environment, Django 1.9 drops Python 3.3 support
dulacp Oct 16, 2015
54961f5
Merge branch 'django-1.9-compat' from @dulaccc into master
palazzem Oct 16, 2015
82fe41c
Use compact syntax for tox envs
dulacp Oct 16, 2015
ba798e4
Add the py35-django19 env to travis but allow it to fail
dulacp Oct 16, 2015
305cfc1
Merge pull request #309 from Photonomie/prepare-for-python35
synasius Oct 16, 2015
13eff3b
Merge pull request #308 from Photonomie/simplify-tox-syntax
synasius Oct 16, 2015
f4d27ca
Added test for pluggable serverclass
Psykopear Oct 22, 2015
3960084
Merge branch 'oauthlib_server_class'
Psykopear Oct 22, 2015
a5d9e68
Changelog updated
Psykopear Oct 22, 2015
71e62fe
Added python 3.5 and Django 1.9 to requirements
Psykopear Oct 22, 2015
3a99442
Docs changelog updated
Psykopear Oct 22, 2015
58f02a1
updated support for django and python
synasius Nov 19, 2015
9d5b939
improved test matrix
synasius Nov 20, 2015
3d3a75c
added support for python3.2
synasius Nov 20, 2015
38992be
python3.5 envs allowed to fail
synasius Nov 20, 2015
772dbed
updated travis config for python3.5 ...again
synasius Nov 20, 2015
ca513fe
updated changelog and the list of supported python and django versions
synasius Nov 20, 2015
2f64b96
removed references to syncdb
synasius Nov 20, 2015
95442d2
Fix typo
burnash Nov 14, 2015
43c1b5b
application registration view uses custom application model in form c…
synasius Nov 20, 2015
e8e3af2
updated changelog
synasius Nov 20, 2015
cd46299
Issue #148 cleanup of expired tokens
trbs May 18, 2015
32c8053
improve variable checking in clear_expired
trbs Nov 1, 2015
d2c8b96
add documentation for refresh_token_expire_seconds
trbs Nov 1, 2015
96fbbf7
updated changelog
synasius Nov 23, 2015
91d12c6
Fixed issue 40
outsbart Oct 30, 2015
88f5d01
removed useless print
outsbart Oct 30, 2015
797cae2
Splitted AuthorizedToken TestCase in two Test cases
outsbart Nov 23, 2015
d1e6799
moved to pytest
synasius Nov 26, 2015
54fa0aa
added doc for token views
outsbart Dec 11, 2015
bee961f
If AccessToken/Grant had, for w/e reason, no "expires", is_expired ch…
teuneboon Oct 19, 2015
f9bc2aa
Added unit tests for expires can be None change
teuneboon Oct 19, 2015
e4c4086
Fixed reversed True/False logic in unit test for expires_can_be_none
teuneboon Oct 19, 2015
6e4b0cb
Removed trailing whitespaces
Psykopear Dec 14, 2015
d0393b3
Added possibility to specify a default list of scopes
Psykopear Oct 29, 2015
9924b26
Added doc for DEFAULT_SCOPES setting
Psykopear Nov 19, 2015
8b66536
Fixed DEFAULT_SCOPES to be a list
Psykopear Nov 20, 2015
b657772
fixed _DEFAULT_SCOPES for testing
synasius Nov 25, 2015
bb4f092
Fixed tox.ini
Psykopear Nov 20, 2015
2ee2b6a
Added test for default scopes in implicit grant
Psykopear Dec 14, 2015
4d51503
Added doc for cleartokens command
outsbart Dec 14, 2015
970ccee
Added AppConfig
outsbart Dec 14, 2015
a818764
added missing swappable migration option to prevent the creation of t…
bartdag Dec 8, 2015
c904ba8
Fixed django versions in tox.ini
Psykopear Dec 14, 2015
53c47a9
ignored .cache folder
synasius Dec 14, 2015
2bf3fb9
updated changelog
synasius Dec 14, 2015
71675f8
updated setup.py requirements and metadata
synasius Dec 14, 2015
6d64220
updated development requirements
synasius Dec 14, 2015
21c6f25
bumped version to 0.10.0
synasius Dec 14, 2015
df5d5a1
wrapping pytest.main() call in the runtests.py; fixing the script exi…
palazzem Dec 15, 2015
6c88b25
Fix #340 by defaulting encoding var when request.encoding is None (wh…
dougkeen Jan 5, 2016
13ed73b
Removed unused imports
outsbart Dec 15, 2015
53b8015
removed django 1.6 compatibility settings
synasius Mar 10, 2016
8201b81
updated test matrix
synasius Mar 10, 2016
6c5da58
removed django17 from .travis.yml
synasius Mar 10, 2016
63230fd
Merge branch 'fix-issue-340' of https://github.com/dougkeen/django-oa…
synasius Mar 10, 2016
e8e7980
removed old compatibility code for django < 1.8
synasius Mar 11, 2016
98b078d
removed south_migrations since support for django<1.8 was dropped
synasius Mar 11, 2016
b751b08
removed django1.4 specific code
synasius Mar 11, 2016
9b28c9e
fixed AppsRegistryNotReady errors in docs build
synasius Mar 11, 2016
167c6c3
relax user constraint on AbstractApplication model
poswald Mar 17, 2016
b2cbf29
relax user constraint on AbstractApplication model
poswald Mar 17, 2016
3074e8c
Update changelog
poswald Mar 17, 2016
7cba4a5
added more information about how to report security issues
palazzem Mar 21, 2016
5513f11
Copy-edit
slashme Apr 22, 2016
f28496c
Small documentation fixes
poswald May 13, 2016
06378b5
Don't encourage adding the application urls without dealing security …
poswald May 13, 2016
e6fc1a9
Convert readthedocs link for their .org -> .io migration for hosted p…
May 31, 2016
fb5cda0
Define urls such that they are namespaced properly and forward-compat…
poswald Jun 1, 2016
da7e6ba
Typo: "beofre" -> "before"
slashme Jun 5, 2016
cf6d333
Merge pull request #372 from slashme/patch-1
poswald Jun 5, 2016
c6bf50b
Merge pull request #390 from adamchainz/readthedocs.io
poswald Jun 5, 2016
dbc4702
Merge pull request #379 from poswald/docs-application-urls
poswald Jun 28, 2016
6fcb8b5
added an IsAuthenticatedOrTokenHasScope Permission
Jun 29, 2016
9c86cfa
import permission into rest_framework
Jun 29, 2016
233498f
added tests, fixed an error the tests revealed
Jun 30, 2016
46d136f
added documentation, info to the readme, changelog and added myself t…
Jun 30, 2016
ac66d9e
Merge remote-tracking branch 'upstream/master' into feature/custom-ac…
abastian Oct 6, 2016
95ed1de
missing on merge with upstream/master
abastian Oct 6, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ __pycache__
pip-log.txt

# Unit test / coverage reports
.cache
.coverage
.tox
nosetests.xml
Expand Down
28 changes: 13 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
language: python
python: "2.7"
python:
- "3.5"

sudo: false

env:
- TOX_ENV=py26-django14
- TOX_ENV=py26-django15
- TOX_ENV=py26-django16
- TOX_ENV=py27-django14
- TOX_ENV=py27-django15
- TOX_ENV=py27-django16
- TOX_ENV=py27-django17
- TOX_ENV=py27-django18
- TOX_ENV=py33-django15
- TOX_ENV=py33-django16
- TOX_ENV=py33-django17
- TOX_ENV=py27-django19
- TOX_ENV=py32-django18
- TOX_ENV=py33-django18
- TOX_ENV=py34-django15
- TOX_ENV=py34-django16
- TOX_ENV=py34-django17
- TOX_ENV=py34-django18
- TOX_ENV=py34-django19
- TOX_ENV=py35-django18
- TOX_ENV=py35-django19
- TOX_ENV=docs

matrix:
fast_finish: true

install:
- pip install tox
- pip install tox "virtualenv<14"
- pip install coveralls

script:
Expand Down
5 changes: 5 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ David Fischer
Ash Christopher
Rodney Richardson
Hiroki Kiyohara
Diego Garcia
Bas van Oostveen
Bart Merenda
Paul Oswald
Jens Timmerman
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Contributing
============

Thanks for your interest! We love contributions, so please feel free to fix bugs, improve things, provide documentation. Just `follow the
guidelines <https://django-oauth-toolkit.readthedocs.org/en/latest/contributing.html>`_ and submit a PR.
guidelines <https://django-oauth-toolkit.readthedocs.io/en/latest/contributing.html>`_ and submit a PR.
40 changes: 36 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,23 @@ Contributing
------------

We love contributions, so please feel free to fix bugs, improve things, provide documentation. Just `follow the
guidelines <https://django-oauth-toolkit.readthedocs.org/en/latest/contributing.html>`_ and submit a PR.
guidelines <https://django-oauth-toolkit.readthedocs.io/en/latest/contributing.html>`_ and submit a PR.

Reporting security issues
-------------------------

If you believe you've found an issue with security implications, please send a detailed description via email to **[email protected]**.
Mail sent to that address reaches the Django OAuth Toolkit core team, who can solve (or forward) the security issue as soon as possible. After
our acknowledge, we may decide to open a public discussion in our mailing list or issues tracker.

Once you’ve submitted an issue via email, you should receive a response from the core team within 48 hours, and depending on the action to be
taken, you may receive further followup emails.

Requirements
------------

* Python 2.6, 2.7, 3.3, 3.4
* Django 1.4, 1.5, 1.6, 1.7, 1.8
* Python 2.7, 3.2, 3.3, 3.4, 3.5
* Django 1.7, 1.8, 1.9

Installation
------------
Expand Down Expand Up @@ -70,7 +80,7 @@ Notice that `oauth2_provider` namespace is mandatory.
Documentation
--------------

The `full documentation <https://django-oauth-toolkit.readthedocs.org/>`_ is on *Read the Docs*.
The `full documentation <https://django-oauth-toolkit.readthedocs.io/>`_ is on *Read the Docs*.

License
-------
Expand All @@ -87,6 +97,28 @@ Roadmap / Todo list (help wanted)
Changelog
---------

Development
~~~~~~~~~~~

* #396: added an IsAuthenticatedOrTokenHasScope Permission
* #357: Support multiple-user clients by allowing User to be NULL for Applications

0.10.0 [2015-12-14]
~~~~~~~~~~~~~~~~~~~

* **#322: dropping support for python 2.6 and django 1.4, 1.5, 1.6**
* #310: Fixed error that could occur sometimes when checking validity of incomplete AccessToken/Grant
* #333: Added possibility to specify the default list of scopes returned when scope parameter is missing
* #325: Added management views of issued tokens
* #249: Added a command to clean expired tokens
* #323: Application registration view uses custom application model in form class
* #299: 'server_class' is now pluggable through Django settings
* #309: Add the py35-django19 env to travis
* #308: Use compact syntax for tox envs
* #306: Django 1.9 compatibility
* #288: Put additional information when generating token responses
* #297: Fixed doc about SessionAuthenticationMiddleware
* #273: Generic read write scope by resource

0.9.0 [2015-07-28]
~~~~~~~~~~~~~~~~~~
Expand Down
6 changes: 3 additions & 3 deletions docs/advanced_topics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ That's all, now Django OAuth Toolkit will use your model wherever an Application
Skip authorization form
=======================

Depending on the OAuth2 flow in use and the access token policy, users might be prompted for the
same authorization multiple times: sometimes this is acceptable or even desiderable but other it isn't.
To control DOT behaviour you can use `approval_prompt` parameter when hitting the authorization endpoint.
Depending on the OAuth2 flow in use and the access token policy, users might be prompted for the
same authorization multiple times: sometimes this is acceptable or even desirable but other times it isn't.
To control DOT behaviour you can use the `approval_prompt` parameter when hitting the authorization endpoint.
Possible values are:

* `force` - users are always prompted for authorization.
Expand Down
25 changes: 25 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
Changelog
=========

Development
~~~~~~~~~~~

* #396: added an IsAuthenticatedOrTokenHasScope Permission
* #357: Support multiple-user clients by allowing User to be NULL for Applications


0.10.0 [2015-12-14]
------------------

* **#322: dropping support for python 2.6 and django 1.4, 1.5, 1.6**
* #310: Fixed error that could occur sometimes when checking validity of incomplete AccessToken/Grant
* #333: Added possibility to specify the default list of scopes returned when scope parameter is missing
* #325: Added management views of issued tokens
* #249: Added a command to clean expired tokens
* #323: Application registration view uses custom application model in form class
* #299: 'server_class' is now pluggable through Django settings
* #309: Add the py35-django19 env to travis
* #308: Use compact syntax for tox envs
* #306: Django 1.9 compatibility
* #288: Put additional information when generating token responses
* #297: Fixed doc about SessionAuthenticationMiddleware
* #273: Generic read write scope by resource


0.9.0 [2015-07-28]
------------------

Expand Down
5 changes: 4 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
here = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, here)
sys.path.insert(0, os.path.dirname(here))
sys.path.insert(0, os.path.join(os.path.dirname(here), 'example'))

os.environ['DJANGO_SETTINGS_MODULE'] = 'oauth2_provider.tests.settings'

import django
django.setup()

import oauth2_provider

# -- General configuration -----------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ of the pull request.
Pull upstream changes into your fork regularly
==============================================

It's a good practice to pull upstream changes from master into your fork on a regular basis, infact if you work on
It's a good practice to pull upstream changes from master into your fork on a regular basis, in fact if you work on
outdated code and your changes diverge too far from master, the pull request has to be rejected.

To pull in upstream changes::
Expand Down Expand Up @@ -85,7 +85,7 @@ Add the tests!
--------------

Whenever you add code, you have to add tests as well. We cannot accept untested code, so unless it is a peculiar
situation you previously discussed with the core commiters, if your pull request reduces the test coverage it will be
situation you previously discussed with the core committers, if your pull request reduces the test coverage it will be
**immediately rejected**.

Code conventions matter
Expand Down
5 changes: 3 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ If you need support please send a message to the `Django OAuth Toolkit Google Gr
Requirements
------------

* Python 2.6, 2.7, 3.3, 3.4
* Django 1.4, 1.5, 1.6, 1.7
* Python 2.7, 3.2, 3.3, 3.4, 3.5
* Django 1.7, 1.8, 1.9

Index
=====
Expand All @@ -38,6 +38,7 @@ Index
models
advanced_topics
settings
management_commands
glossary

.. toctree::
Expand Down
1 change: 0 additions & 1 deletion docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Sync your database

.. sourcecode:: sh

$ python manage.py syncdb
$ python manage.py migrate oauth2_provider

Next step is our :doc:`first tutorial <tutorial/tutorial_01>`.
20 changes: 20 additions & 0 deletions docs/management_commands.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Management commands
===================

Django OAuth Toolkit exposes some useful management commands that can be run via shell or by other means (eg: cron)

.. _cleartokens:

cleartokens
~~~~~~~~~~~

The ``cleartokens`` management command allows the user to remove those refresh tokens whose lifetime is greater than the
amount specified by ``REFRESH_TOKEN_EXPIRE_SECONDS`` settings. It is important that this command is run regularly
(eg: via cron) to avoid cluttering the database with expired refresh tokens.

If ``cleartokens`` runs daily the maximum delay before a refresh token is
removed is ``REFRESH_TOKEN_EXPIRE_SECONDS`` + 1 day. This is normally not a
problem since refresh tokens are long lived.

Note: Refresh tokens need to expire before AccessTokens can be removed from the
database. Using ``cleartokens`` without ``REFRESH_TOKEN_EXPIRE_SECONDS`` has limited effect.
33 changes: 33 additions & 0 deletions docs/rest-framework/permissions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,36 @@ For example:

When a request is performed both the `READ_SCOPE` \\ `WRITE_SCOPE` and 'music' scopes are required to be authorized for the current access token.

TokenHasResourceScope
----------------------
The `TokenHasResourceScope` permission class allows the access only when the current access token has been authorized for **all** the scopes listed in the `required_scopes` field of the view but according of request's method.

When the current request's method is one of the "safe" methods, the access is allowed only if the access token has been authorized for the `scope:read` scope (for example `music:read`).
When the request's method is one of "non safe" methods, the access is allowed only if the access token has been authorizes for the `scope:write` scope (for example `music:write`).

.. code-block:: python

class SongView(views.APIView):
authentication_classes = [OAuth2Authentication]
permission_classes = [TokenHasResourceScope]
required_scopes = ['music']

The `required_scopes` attribute is mandatory (you just need inform the resource scope).


IsAuthenticatedOrTokenHasScope
------------------------------
The `TokenHasResourceScope` permission class allows the access only when the current access token has been authorized for **all** the scopes listed in the `required_scopes` field of the view but according of request's method.
And also allows access to Authenticated users who are authenticated in django, but were not authenticated trought the OAuth2Authentication class.
This allows for protection of the api using scopes, but still let's users browse the full browseable API.
To restrict users to only browse the parts of the browseable API they should be allowed to see, you can combine this wwith the DjangoModelPermission or the DjangoObjectPermission.

For example:

.. code-block:: python

class SongView(views.APIView):
permission_classes = [IsAuthenticatedOrTokenHasScope, DjangoModelPermission]
required_scopes = ['music']

The `required_scopes` attribute is mandatory.
21 changes: 20 additions & 1 deletion docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ CLIENT_SECRET_GENERATOR_LENGTH
The length of the generated secrets, in characters. If this value is too low,
secrets may become subject to bruteforce guessing.

OAUTH2_SERVER_CLASS
~~~~~~~~~~~~~~~~~~~~
The import string for the ``server_class`` (or ``oauthlib.oauth2.Server`` subclass)
used in the ``OAuthLibMixin`` that implements OAuth2 grant types.

OAUTH2_VALIDATOR_CLASS
~~~~~~~~~~~~~~~~~~~~~~
The import string of the ``oauthlib.oauth2.RequestValidator`` subclass that
Expand All @@ -71,7 +76,16 @@ to get a ``Server`` instance.

SCOPES
~~~~~~
A dictionnary mapping each scope name to its human description.
A dictionary mapping each scope name to its human description.

DEFAULT_SCOPES
~~~~~~~~~~~~~~
A list of scopes that should be returned by default.
This is a subset of the keys of the SCOPES setting.
By default this is set to '__all__' meaning that the whole set of SCOPES will be returned.
.. code-block:: python

DEFAULT_SCOPES = ['read', 'write']

READ_SCOPE
~~~~~~~~~~
Expand All @@ -81,6 +95,11 @@ WRITE_SCOPE
~~~~~~~~~~~
The name of the *write* scope.

REFRESH_TOKEN_EXPIRE_SECONDS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The number of seconds before a refresh token gets removed from the database by
the ``cleartokens`` management command. Check :ref:`cleartokens` management command for further info.

REQUEST_APPROVAL_PROMPT
~~~~~~~~~~~~~~~~~~~~~~~
Can be ``'force'`` or ``'auto'``.
Expand Down
Loading