Skip to content

Commit a473196

Browse files
authored
Merge pull request #4 from skruger/newdjango
Update for Django 1.11-2.1
2 parents d3ad31f + 2ca8e8d commit a473196

29 files changed

+241
-593
lines changed

.travis.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1+
sudo: false
12
language: python
2-
env:
3-
- DJANGO="django>=1.7,<1.9"
43
python:
54
- "2.7"
6-
# command to install dependencies
7-
install:
8-
- pip install -q -r requirements.txt
9-
- pip install sqlparse
10-
- pip install -q $DJANGO --upgrade
11-
- python setup.py develop
12-
script: ./test.sh
5+
- "3.6"
6+
install: pip install tox-travis
7+
script: tox

Vagrantfile

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# All Vagrant configuration is done below. The "2" in Vagrant.configure
5+
# configures the configuration version (we support older styles for
6+
# backwards compatibility). Please don't change it unless you know what
7+
# you're doing.
8+
Vagrant.configure(2) do |config|
9+
# The most common configuration options are documented and commented below.
10+
# For a complete reference, please see the online documentation at
11+
# https://docs.vagrantup.com.
12+
13+
# Every Vagrant development environment requires a box. You can search for
14+
# boxes at https://atlas.hashicorp.com/search.
15+
config.vm.box = "ubuntu/bionic64"
16+
17+
# Disable automatic box update checking. If you disable this, then
18+
# boxes will only be checked for updates when the user runs
19+
# `vagrant box outdated`. This is not recommended.
20+
# config.vm.box_check_update = false
21+
22+
# Create a forwarded port mapping which allows access to a specific port
23+
# within the machine from a port on the host machine. In the example below,
24+
# accessing "localhost:8080" will access port 80 on the guest machine.
25+
# config.vm.network "forwarded_port", guest: 80, host: 8080
26+
# config.vm.network "forwarded_port", guest: 8000, host: 8000
27+
28+
# Create a private network, which allows host-only access to the machine
29+
# using a specific IP.
30+
# config.vm.network "private_network", ip: "192.168.33.10"
31+
32+
# Create a public network, which generally matched to bridged network.
33+
# Bridged networks make the machine appear as another physical device on
34+
# your network.
35+
# config.vm.network "public_network"
36+
37+
# Share an additional folder to the guest VM. The first argument is
38+
# the path on the host to the actual folder. The second argument is
39+
# the path on the guest to mount the folder. And the optional third
40+
# argument is a set of non-required options.
41+
# config.vm.synced_folder "../data", "/vagrant_data"
42+
43+
# Provider-specific configuration so you can fine-tune various
44+
# backing providers for Vagrant. These expose provider-specific options.
45+
# Example for VirtualBox:
46+
#
47+
config.vm.provider "virtualbox" do |vb|
48+
# Display the VirtualBox GUI when booting the machine
49+
# vb.gui = true
50+
# Customize the amount of memory on the VM:
51+
vb.memory = "1024"
52+
end
53+
#
54+
# View the documentation for the provider you are using for more
55+
# information on available options.
56+
57+
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
58+
# such as FTP and Heroku are also available. See the documentation at
59+
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
60+
# config.push.define "atlas" do |push|
61+
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
62+
# end
63+
64+
# Enable provisioning with a shell script. Additional provisioners such as
65+
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
66+
# documentation for more information about their specific syntax and use.
67+
config.vm.provision "shell", privileged: false, inline: <<-SHELL
68+
sudo resize2fs /dev/sda1
69+
sudo apt-get update
70+
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
71+
72+
sudo -H pip install tox
73+
74+
echo "export TOX_WORK_DIR=/tmp/" >> ~/.bash_aliases
75+
76+
SHELL
77+
end

docs/changes.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
v 2.0
2+
-----
3+
* Update for current Django 1.11, 2.0, and 2.1.
4+
5+
v 1.2
6+
-----
7+
Updated to make skopes configurable in the database and update for Django 1.7
8+
9+
v 1.0
10+
-----
11+
Forked from original project at caffeinehit/django-oauth2-provider
112

213
v 0.2
314
-----
415
* *Breaking change* Moved ``provider.oauth2.scope`` to ``provider.scope``
516
* *Breaking change* Replaced the write scope with a new write scope that includes reading
617
* Default scope for new ``provider.oauth2.models.AccessToken`` is now ``provider.constants.SCOPES[0][0]``
7-
* Access token response returns a space seperated list of scopes instead of an integer value
18+
* Access token response returns a space seperated list of scopes instead of an integer value

provider/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.2"
1+
__version__ = "2.0"

provider/compat/urls.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

provider/forms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _clean_fields(self):
5151
"""
5252
try:
5353
super(OAuthForm, self)._clean_fields()
54-
except OAuthValidationError, e:
54+
except OAuthValidationError as e:
5555
self._errors.update(e.args[0])
5656

5757
def _clean_form(self):
@@ -60,5 +60,5 @@ def _clean_form(self):
6060
"""
6161
try:
6262
super(OAuthForm, self)._clean_form()
63-
except OAuthValidationError, e:
63+
except OAuthValidationError as e:
6464
self._errors.update(e.args[0])

provider/oauth2/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
import backends
2-
import forms
3-
import models
4-
import urls
5-
import views
6-
71
default_app_config = 'provider.oauth2.apps.Oauth2'

provider/oauth2/backends.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import base64
2+
13
from provider.utils import now
24
from provider.oauth2.forms import ClientAuthForm, PublicPasswordGrantForm
35
from provider.oauth2.models import AccessToken
@@ -28,8 +30,9 @@ def authenticate(self, request=None):
2830
return None
2931

3032
try:
31-
basic, base64 = auth.split(' ')
32-
client_id, client_secret = base64.decode('base64').split(':')
33+
basic, enc_user_passwd = auth.split(' ')
34+
user_pass = base64.b64decode(enc_user_passwd).decode('utf8')
35+
client_id, client_secret = user_pass.split(':')
3336

3437
form = ClientAuthForm({
3538
'client_id': client_id,
@@ -53,7 +56,11 @@ def authenticate(self, request=None):
5356
if request is None:
5457
return None
5558

56-
form = ClientAuthForm(request.REQUEST)
59+
if hasattr(request, 'REQUEST'):
60+
args = request.REQUEST
61+
else:
62+
args = request.POST or request.GET
63+
form = ClientAuthForm(args)
5764

5865
if form.is_valid():
5966
return form.cleaned_data.get('client')
@@ -74,7 +81,11 @@ def authenticate(self, request=None):
7481
if request is None:
7582
return None
7683

77-
form = PublicPasswordGrantForm(request.REQUEST)
84+
if hasattr(request, 'REQUEST'):
85+
args = request.REQUEST
86+
else:
87+
args = request.POST or request.GET
88+
form = PublicPasswordGrantForm(args)
7889

7990
if form.is_valid():
8091
return form.cleaned_data.get('client')

provider/oauth2/forms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
from six import string_types
12
from django import forms
23
from django.contrib.auth import authenticate
34
from django.conf import settings
4-
from django.utils.encoding import smart_unicode
55
from django.utils.translation import ugettext as _
66
from provider.constants import RESPONSE_TYPE_CHOICES, SCOPES
77
from provider.forms import OAuthForm, OAuthValidationError
@@ -52,7 +52,7 @@ class ScopeModelChoiceField(forms.ModelMultipleChoiceField):
5252
# widget = forms.TextInput
5353

5454
def to_python(self, value):
55-
if isinstance(value, basestring):
55+
if isinstance(value, string_types):
5656
return [s for s in value.split(' ') if s != '']
5757
else:
5858
return value
@@ -160,7 +160,7 @@ def save(self, **kwargs):
160160

161161
grant = Grant(**kwargs)
162162
grant.save()
163-
grant.scope = self.cleaned_data.get('scope')
163+
grant.scope.set(self.cleaned_data.get('scope'))
164164
return grant
165165

166166

provider/oauth2/migrations/0001_initial.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Migration(migrations.Migration):
4747
('client_secret', models.CharField(default=provider.utils.long_token, max_length=255)),
4848
('client_type', models.IntegerField(choices=[(0, b'Confidential (Web applications)'), (1, b'Public (Native and JS applications)')])),
4949
('auto_authorize', models.BooleanField(default=False)),
50-
('user', models.ForeignKey(related_name='oauth2_client', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
50+
('user', models.ForeignKey(related_name='oauth2_client', blank=True, to=settings.AUTH_USER_MODEL, null=True, on_delete=models.DO_NOTHING)),
5151
],
5252
options={
5353
'db_table': 'oauth2_client',
@@ -61,7 +61,7 @@ class Migration(migrations.Migration):
6161
('code', models.CharField(default=provider.utils.long_token, max_length=255)),
6262
('expires', models.DateTimeField(default=provider.utils.get_code_expiry)),
6363
('redirect_uri', models.CharField(max_length=255, blank=True)),
64-
('client', models.ForeignKey(to='oauth2.Client')),
64+
('client', models.ForeignKey(to='oauth2.Client', on_delete=models.DO_NOTHING)),
6565
],
6666
options={
6767
'db_table': 'oauth2_grant',
@@ -74,9 +74,9 @@ class Migration(migrations.Migration):
7474
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
7575
('token', models.CharField(default=provider.utils.long_token, max_length=255)),
7676
('expired', models.BooleanField(default=False)),
77-
('access_token', models.OneToOneField(related_name='refresh_token', to='oauth2.AccessToken')),
78-
('client', models.ForeignKey(to='oauth2.Client')),
79-
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
77+
('access_token', models.OneToOneField(related_name='refresh_token', to='oauth2.AccessToken', on_delete=models.DO_NOTHING)),
78+
('client', models.ForeignKey(to='oauth2.Client', on_delete=models.DO_NOTHING)),
79+
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING)),
8080
],
8181
options={
8282
'db_table': 'oauth2_refreshtoken',
@@ -103,13 +103,13 @@ class Migration(migrations.Migration):
103103
migrations.AddField(
104104
model_name='grant',
105105
name='user',
106-
field=models.ForeignKey(to=settings.AUTH_USER_MODEL),
106+
field=models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING),
107107
preserve_default=True,
108108
),
109109
migrations.AddField(
110110
model_name='authorizedclient',
111111
name='client',
112-
field=models.ForeignKey(to='oauth2.Client'),
112+
field=models.ForeignKey(to='oauth2.Client', on_delete=models.DO_NOTHING),
113113
preserve_default=True,
114114
),
115115
migrations.AddField(
@@ -121,7 +121,7 @@ class Migration(migrations.Migration):
121121
migrations.AddField(
122122
model_name='authorizedclient',
123123
name='user',
124-
field=models.ForeignKey(related_name='oauth2_authorized_client', to=settings.AUTH_USER_MODEL),
124+
field=models.ForeignKey(related_name='oauth2_authorized_client', to=settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING),
125125
preserve_default=True,
126126
),
127127
migrations.AlterUniqueTogether(
@@ -131,7 +131,7 @@ class Migration(migrations.Migration):
131131
migrations.AddField(
132132
model_name='accesstoken',
133133
name='client',
134-
field=models.ForeignKey(to='oauth2.Client'),
134+
field=models.ForeignKey(to='oauth2.Client', on_delete=models.DO_NOTHING),
135135
preserve_default=True,
136136
),
137137
migrations.AddField(
@@ -143,7 +143,7 @@ class Migration(migrations.Migration):
143143
migrations.AddField(
144144
model_name='accesstoken',
145145
name='user',
146-
field=models.ForeignKey(to=settings.AUTH_USER_MODEL),
146+
field=models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING),
147147
preserve_default=True,
148148
),
149149
migrations.RunSQL("INSERT INTO oauth2_scope (name, description) values ('read', 'Read-Only access') "),

0 commit comments

Comments
 (0)