Improve handle of client_secret with client_types.

This commit is contained in:
Ignacio Fiorentino 2016-04-05 18:31:08 -03:00
parent fa2c7d314d
commit a3247db273
3 changed files with 34 additions and 3 deletions

View file

@ -30,10 +30,21 @@ class ClientForm(ModelForm):
def clean_client_secret(self):
instance = getattr(self, 'instance', None)
secret = ''
print self.cleaned_data
if instance and instance.pk:
return instance.client_secret
if (self.cleaned_data['client_type'] == 'confidential') and not instance.client_secret:
secret = md5(uuid4().hex.encode()).hexdigest()
elif (self.cleaned_data['client_type'] == 'confidential') and instance.client_secret:
secret = instance.client_secret
else:
return md5(uuid4().hex.encode()).hexdigest()
if (instance.client_type == 'confidential'):
secret = md5(uuid4().hex.encode()).hexdigest()
return secret
@admin.register(Client)

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-04-05 20:41
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('oidc_provider', '0011_client_client_type'),
]
operations = [
migrations.AlterField(
model_name='client',
name='client_secret',
field=models.CharField(blank=True, default=b'', max_length=255),
),
]

View file

@ -24,7 +24,7 @@ class Client(models.Model):
name = models.CharField(max_length=100, default='')
client_type = models.CharField(max_length=30, choices=CLIENT_TYPE_CHOICES, default='confidential', help_text=_(u'<b>Confidential</b> clients are capable of maintaining the confidentiality of their credentials. <b>Public</b> clients are incapable.'))
client_id = models.CharField(max_length=255, unique=True)
client_secret = models.CharField(max_length=255, unique=True)
client_secret = models.CharField(max_length=255, blank=True, default='')
response_type = models.CharField(max_length=30, choices=RESPONSE_TYPE_CHOICES)
date_created = models.DateField(auto_now_add=True)