Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various improvements #67

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
63 changes: 55 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,55 @@
*.pyc
.DS_Store
_build
.*.sw[po]
*.egg-info
dist
build
venv
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# Backup files
*~

# C extensions
*.so

# Distribution / packaging
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

# Sphinx documentation
docs/_build/

data/*.sqlite*
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions provider/forms.py → djoauth2/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: 6 additions & 0 deletions djoauth2/oauth2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from . import backends
from . import forms
from . import managers
from . import models
from . import urls
from . import views
6 changes: 4 additions & 2 deletions provider/oauth2/admin.py → djoauth2/oauth2/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib import admin
from .models import AccessToken, Grant, Client, RefreshToken
from .models import AccessToken, Grant, BasicClient, RefreshToken, Client


class AccessTokenAdmin(admin.ModelAdmin):
Expand All @@ -18,5 +18,7 @@ class ClientAdmin(admin.ModelAdmin):

admin.site.register(AccessToken, AccessTokenAdmin)
admin.site.register(Grant, GrantAdmin)
admin.site.register(Client, ClientAdmin)
if Client == BasicClient:
# Only if we are not overriding the BasicClient
admin.site.register(BasicClient, ClientAdmin)
admin.site.register(RefreshToken)
7 changes: 5 additions & 2 deletions provider/oauth2/backends.py → djoauth2/oauth2/backends.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ..utils import now
from .forms import ClientAuthForm, PublicPasswordGrantForm
from .models import AccessToken
import base64


class BaseBackend(object):
Expand Down Expand Up @@ -28,8 +29,10 @@ def authenticate(self, request=None):
return None

try:
basic, base64 = auth.split(' ')
client_id, client_secret = base64.decode('base64').split(':')
basic, b64string = auth.decode("utf-8").split(' ')
s = base64.b64decode(b64string).decode("utf-8")
client_id, client_secret = s.split(':')


form = ClientAuthForm({
'client_id': client_id,
Expand Down
62 changes: 62 additions & 0 deletions djoauth2/oauth2/fixtures/test_oauth2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[
{
"fields": {
"redirect_uri": "http://example.com/application/1/",
"client_id": "90a4a24ffefe7ebbae2c",
"client_secret": "35c25066023f32c4f098d1e40de94f07f98c1acf",
"client_type": 0,
"url": "http://example.com/",
"users": [1]
},
"model": "oauth2.basicclient",
"pk": 1
},
{
"fields": {
"redirect_uri": "http://example.com/application/2/",
"client_id": "71fbc29950ac1b386a12",
"client_secret": "1944b695ca0cbf4f419a7d5c7e4fed13a660bc04",
"client_type": 0,
"url": "http://example.com/",
"users": [2]
},
"model": "oauth2.basicclient",
"pk": 2
},
{
"fields": {
"date_joined": "2012-01-23 05:44:17",
"email": "[email protected]",
"first_name": "",
"groups": [],
"is_active": true,
"is_staff": true,
"is_superuser": true,
"last_login": "2012-01-23 05:52:32",
"last_name": "",
"password": "sha1$da29e$498b9faab2d002183bc1d874689634b0e15ad6d7",
"user_permissions": [],
"username": "test-user-1"
},
"model": "auth.user",
"pk": 1
},
{
"fields": {
"date_joined": "2012-01-23 05:53:31",
"email": "",
"first_name": "",
"groups": [],
"is_active": true,
"is_staff": false,
"is_superuser": false,
"last_login": "2012-01-23 05:53:31",
"last_name": "",
"password": "sha1$0cf1b$d66589690edd96b410170fcae5cc2bdfb68821e7",
"user_permissions": [],
"username": "test-user-2"
},
"model": "auth.user",
"pk": 2
}
]
10 changes: 7 additions & 3 deletions provider/oauth2/forms.py → djoauth2/oauth2/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django import forms
from django.contrib.auth import authenticate
from django.utils.encoding import smart_unicode
from django.utils.translation import ugettext as _
from .. import scope
from ..constants import RESPONSE_TYPE_CHOICES, SCOPES
Expand Down Expand Up @@ -65,7 +64,7 @@ def to_python(self, value):
value = value.split(' ')

# Split values into list
return u' '.join([smart_unicode(val) for val in value]).split(u' ')
return value

def validate(self, value):
"""
Expand Down Expand Up @@ -151,7 +150,7 @@ def clean_response_type(self):
if type not in RESPONSE_TYPE_CHOICES:
raise OAuthValidationError({
'error': 'unsupported_response_type',
'error_description': u"'%s' is not a supported response "
'error_description': "'%s' is not a supported response "
"type." % type})

return response_type
Expand Down Expand Up @@ -309,6 +308,9 @@ def clean(self):


class PublicPasswordGrantForm(PasswordGrantForm):
"""
Validates username, password, client
"""
client_id = forms.CharField(required=True)
grant_type = forms.CharField(required=True)

Expand All @@ -321,8 +323,10 @@ def clean_grant_type(self):
return grant_type

def clean(self):
# check username + password
data = super(PublicPasswordGrantForm, self).clean()

# Check client
try:
client = Client.objects.get(client_id=data.get('client_id'))
except Client.DoesNotExist:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from south.v2 import SchemaMigration
from django.db import models

from provider.compat import user_model_label
from djoauth2.compat import user_model_label


class Migration(SchemaMigration):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from south.v2 import SchemaMigration
from django.db import models

from provider.compat import user_model_label
from djoauth2.compat import user_model_label


class Migration(SchemaMigration):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from south.v2 import SchemaMigration
from django.db import models

from provider.compat import user_model_label
from djoauth2.compat import user_model_label


class Migration(SchemaMigration):
Expand Down
Loading