Skip to content
This repository was archived by the owner on Aug 3, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 4 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
sudo: false
language: python
env:
- DJANGO="django>=1.7,<1.9"
python:
- "2.7"
# command to install dependencies
install:
- pip install -q -r requirements.txt
- pip install sqlparse
- pip install -q $DJANGO --upgrade
- python setup.py develop
script: ./test.sh
- "3.6"
install: pip install tox-travis
script: tox
77 changes: 77 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.

# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "ubuntu/bionic64"

# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
# config.vm.network "forwarded_port", guest: 8000, host: 8000

# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"

# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"

# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"

# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
# vb.gui = true
# Customize the amount of memory on the VM:
vb.memory = "1024"
end
#
# View the documentation for the provider you are using for more
# information on available options.

# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end

# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
config.vm.provision "shell", privileged: false, inline: <<-SHELL
sudo resize2fs /dev/sda1
sudo apt-get update
sudo apt-get install -y build-essential python-dev python-pip python-virtualenv python3-dev python3 python3-virtualenv virtualenv virtualenvwrapper postgresql libpq-dev memcached redis-server redis-tools

sudo -H pip install tox

echo "export TOX_WORK_DIR=/tmp/" >> ~/.bash_aliases

SHELL
end
13 changes: 12 additions & 1 deletion docs/changes.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
v 2.0
-----
* Update for current Django 1.11, 2.0, and 2.1.

v 1.2
-----
Updated to make skopes configurable in the database and update for Django 1.7

v 1.0
-----
Forked from original project at caffeinehit/django-oauth2-provider

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
* Access token response returns a space seperated list of scopes instead of an integer value
2 changes: 1 addition & 1 deletion provider/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2"
__version__ = "2.0"
4 changes: 0 additions & 4 deletions provider/compat/urls.py

This file was deleted.

4 changes: 2 additions & 2 deletions provider/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _clean_fields(self):
"""
try:
super(OAuthForm, self)._clean_fields()
except OAuthValidationError, e:
except OAuthValidationError as e:
self._errors.update(e.args[0])

def _clean_form(self):
Expand All @@ -60,5 +60,5 @@ def _clean_form(self):
"""
try:
super(OAuthForm, self)._clean_form()
except OAuthValidationError, e:
except OAuthValidationError as e:
self._errors.update(e.args[0])
6 changes: 0 additions & 6 deletions provider/oauth2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
import backends
import forms
import models
import urls
import views

default_app_config = 'provider.oauth2.apps.Oauth2'
19 changes: 15 additions & 4 deletions provider/oauth2/backends.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import base64

from provider.utils import now
from provider.oauth2.forms import ClientAuthForm, PublicPasswordGrantForm
from provider.oauth2.models import AccessToken
Expand Down Expand Up @@ -28,8 +30,9 @@ def authenticate(self, request=None):
return None

try:
basic, base64 = auth.split(' ')
client_id, client_secret = base64.decode('base64').split(':')
basic, enc_user_passwd = auth.split(' ')
user_pass = base64.b64decode(enc_user_passwd).decode('utf8')
client_id, client_secret = user_pass.split(':')

form = ClientAuthForm({
'client_id': client_id,
Expand All @@ -53,7 +56,11 @@ def authenticate(self, request=None):
if request is None:
return None

form = ClientAuthForm(request.REQUEST)
if hasattr(request, 'REQUEST'):
args = request.REQUEST
else:
args = request.POST or request.GET
form = ClientAuthForm(args)

if form.is_valid():
return form.cleaned_data.get('client')
Expand All @@ -74,7 +81,11 @@ def authenticate(self, request=None):
if request is None:
return None

form = PublicPasswordGrantForm(request.REQUEST)
if hasattr(request, 'REQUEST'):
args = request.REQUEST
else:
args = request.POST or request.GET
form = PublicPasswordGrantForm(args)

if form.is_valid():
return form.cleaned_data.get('client')
Expand Down
6 changes: 3 additions & 3 deletions provider/oauth2/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from six import string_types
from django import forms
from django.contrib.auth import authenticate
from django.conf import settings
from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext as _
from provider.constants import RESPONSE_TYPE_CHOICES, SCOPES
from provider.forms import OAuthForm, OAuthValidationError
Expand Down Expand Up @@ -52,7 +52,7 @@ class ScopeModelChoiceField(forms.ModelMultipleChoiceField):
# widget = forms.TextInput

def to_python(self, value):
if isinstance(value, basestring):
if isinstance(value, string_types):
return [s for s in value.split(' ') if s != '']
else:
return value
Expand Down Expand Up @@ -160,7 +160,7 @@ def save(self, **kwargs):

grant = Grant(**kwargs)
grant.save()
grant.scope = self.cleaned_data.get('scope')
grant.scope.set(self.cleaned_data.get('scope'))
return grant


Expand Down
20 changes: 10 additions & 10 deletions provider/oauth2/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Migration(migrations.Migration):
('client_secret', models.CharField(default=provider.utils.long_token, max_length=255)),
('client_type', models.IntegerField(choices=[(0, b'Confidential (Web applications)'), (1, b'Public (Native and JS applications)')])),
('auto_authorize', models.BooleanField(default=False)),
('user', models.ForeignKey(related_name='oauth2_client', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
('user', models.ForeignKey(related_name='oauth2_client', blank=True, to=settings.AUTH_USER_MODEL, null=True, on_delete=models.DO_NOTHING)),
],
options={
'db_table': 'oauth2_client',
Expand All @@ -61,7 +61,7 @@ class Migration(migrations.Migration):
('code', models.CharField(default=provider.utils.long_token, max_length=255)),
('expires', models.DateTimeField(default=provider.utils.get_code_expiry)),
('redirect_uri', models.CharField(max_length=255, blank=True)),
('client', models.ForeignKey(to='oauth2.Client')),
('client', models.ForeignKey(to='oauth2.Client', on_delete=models.DO_NOTHING)),
],
options={
'db_table': 'oauth2_grant',
Expand All @@ -74,9 +74,9 @@ class Migration(migrations.Migration):
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('token', models.CharField(default=provider.utils.long_token, max_length=255)),
('expired', models.BooleanField(default=False)),
('access_token', models.OneToOneField(related_name='refresh_token', to='oauth2.AccessToken')),
('client', models.ForeignKey(to='oauth2.Client')),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
('access_token', models.OneToOneField(related_name='refresh_token', to='oauth2.AccessToken', on_delete=models.DO_NOTHING)),
('client', models.ForeignKey(to='oauth2.Client', on_delete=models.DO_NOTHING)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING)),
],
options={
'db_table': 'oauth2_refreshtoken',
Expand All @@ -103,13 +103,13 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='grant',
name='user',
field=models.ForeignKey(to=settings.AUTH_USER_MODEL),
field=models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING),
preserve_default=True,
),
migrations.AddField(
model_name='authorizedclient',
name='client',
field=models.ForeignKey(to='oauth2.Client'),
field=models.ForeignKey(to='oauth2.Client', on_delete=models.DO_NOTHING),
preserve_default=True,
),
migrations.AddField(
Expand All @@ -121,7 +121,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='authorizedclient',
name='user',
field=models.ForeignKey(related_name='oauth2_authorized_client', to=settings.AUTH_USER_MODEL),
field=models.ForeignKey(related_name='oauth2_authorized_client', to=settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING),
preserve_default=True,
),
migrations.AlterUniqueTogether(
Expand All @@ -131,7 +131,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='accesstoken',
name='client',
field=models.ForeignKey(to='oauth2.Client'),
field=models.ForeignKey(to='oauth2.Client', on_delete=models.DO_NOTHING),
preserve_default=True,
),
migrations.AddField(
Expand All @@ -143,7 +143,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='accesstoken',
name='user',
field=models.ForeignKey(to=settings.AUTH_USER_MODEL),
field=models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING),
preserve_default=True,
),
migrations.RunSQL("INSERT INTO oauth2_scope (name, description) values ('read', 'Read-Only access') "),
Expand Down
26 changes: 13 additions & 13 deletions provider/oauth2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Client(models.Model):

Clients are outlined in the :rfc:`2` and its subsections.
"""
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='oauth2_client',
user = models.ForeignKey(settings.AUTH_USER_MODEL, models.DO_NOTHING, related_name='oauth2_client',
blank=True, null=True)
name = models.CharField(max_length=255, blank=True)
url = models.URLField(help_text="Your application's URL.")
Expand Down Expand Up @@ -90,10 +90,10 @@ def set_authorization_scope(self, user, client, scope_list):


class AuthorizedClient(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL,
user = models.ForeignKey(settings.AUTH_USER_MODEL, models.DO_NOTHING,
related_name='oauth2_authorized_client')
client = models.ForeignKey(Client)
scope = models.ManyToManyField(Scope)
client = models.ForeignKey('Client', models.DO_NOTHING)
scope = models.ManyToManyField('Scope')
authorized_at = models.DateTimeField(auto_now_add=True, blank=True)

objects = AuthorizedClientManager()
Expand All @@ -120,12 +120,12 @@ class Grant(models.Model):
* :attr:`redirect_uri`
* :attr:`scope`
"""
user = models.ForeignKey(settings.AUTH_USER_MODEL)
client = models.ForeignKey(Client)
user = models.ForeignKey(settings.AUTH_USER_MODEL, models.DO_NOTHING)
client = models.ForeignKey('Client', models.DO_NOTHING)
code = models.CharField(max_length=255, default=long_token)
expires = models.DateTimeField(default=get_code_expiry)
redirect_uri = models.CharField(max_length=255, blank=True)
scope = models.ManyToManyField(Scope)
scope = models.ManyToManyField('Scope')

def __unicode__(self):
return self.code
Expand Down Expand Up @@ -177,11 +177,11 @@ class AccessToken(models.Model):
* :meth:`get_expire_delta` - returns an integer representing seconds to
expiry
"""
user = models.ForeignKey(settings.AUTH_USER_MODEL)
user = models.ForeignKey(settings.AUTH_USER_MODEL, models.DO_NOTHING)
token = models.CharField(max_length=255, default=long_token, db_index=True)
client = models.ForeignKey(Client)
client = models.ForeignKey('Client', models.DO_NOTHING)
expires = models.DateTimeField()
scope = models.ManyToManyField(Scope)
scope = models.ManyToManyField('Scope')

objects = AccessTokenManager()

Expand Down Expand Up @@ -246,11 +246,11 @@ class RefreshToken(models.Model):
* :attr:`client` - :class:`Client`
* :attr:`expired` - ``boolean``
"""
user = models.ForeignKey(settings.AUTH_USER_MODEL)
user = models.ForeignKey(settings.AUTH_USER_MODEL, models.DO_NOTHING)
token = models.CharField(max_length=255, default=long_token)
access_token = models.OneToOneField(AccessToken,
access_token = models.OneToOneField('AccessToken', models.DO_NOTHING,
related_name='refresh_token')
client = models.ForeignKey(Client)
client = models.ForeignKey('Client', models.DO_NOTHING)
expired = models.BooleanField(default=False)

objects = RefreshTokenManager()
Expand Down
Loading