handle the correctly authorized_scopes attribute format

Closes #5231
This commit is contained in:
Serghei Mihai 2014-08-14 14:14:15 +02:00
parent 6893b249f9
commit 65f1db6ccc
2 changed files with 12 additions and 3 deletions

View File

@ -1,4 +1,5 @@
from django.core.exceptions import ValidationError
from django.core.validators import RegexValidator
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.template import Template
@ -8,15 +9,22 @@ from provider.oauth2.models import Client
from authentic2.models import LogoutUrlAbstract
from authentic2.managers import GetBySlugManager
class A2Client(LogoutUrlAbstract, Client):
authorized_scopes = models.CharField('automatically granted scopes',
max_length=256, blank=True, null=True,
help_text=_('space separated scopes'))
max_length=256, blank=True,
help_text=_('space separated scopes'),
validators = [RegexValidator(('^[a-z]+([ \+][a-z]+)+$'))]
)
class Meta:
verbose_name = _('client')
verbose_name_plural = _('clients')
def clean(self):
self.authorized_scopes = self.authorized_scopes.strip()
class AttributeRelease(models.Model):
client = models.ForeignKey(A2Client, verbose_name=_('client'))

View File

@ -91,7 +91,8 @@ class Authorize(Authorize):
automatic_grant = app_settings.AUTOMATIC_GRANT
if hasattr(client, 'a2client'):
client_scopes = client.a2client.authorized_scopes.split(' ')
client_scopes = client.a2client.authorized_scopes
client_scopes = filter(None, map(unicode.strip, client_scopes.strip().split(' ')))
automatic_grant += ((client.url, client_scopes),)
for url_prefix, scopes in automatic_grant: