Commit 647f556b authored by ubedv's avatar ubedv
Browse files

Merge branch 'usernames' into 'dev'

Usernames

See merge request !1
parents ba94b0f0 8f83dc97
......@@ -3,6 +3,9 @@ import logging
import re
from django.core.exceptions import ImproperlyConfigured
from django.core.validators import RegexValidator, URLValidator
from django.utils.deconstruct import deconstructible
from django.utils.translation import gettext_lazy as _
from django.db import models as db_models
from django_mysql.models import JSONField
from django.conf import settings
......@@ -19,6 +22,16 @@ BEARER_TOKEN_EXTRACTOR = re.compile('^Bearer (.+)$')
OIDC_CLIENT = {}
@deconstructible
class IDPNameValidator(RegexValidator):
regex = r'^[\w\-_ ]+$'
message = (
'Enter a valid IdP name. This value may contain only letters, '
'numbers, and -/_/<space> characters'
)
flags = 0
def scopes_default():
return [
'openid',
......@@ -30,12 +43,22 @@ def scopes_default():
class OIDCConfig(db_models.Model):
name = db_models.CharField(max_length=200)
name = db_models.CharField(
max_length=200,
validators=[
IDPNameValidator(),
],
)
client_id = db_models.CharField(max_length=200)
client_secret = db_models.CharField(max_length=200)
issuer_uri = db_models.CharField(max_length=200)
issuer_uri = db_models.CharField(
max_length=200,
validators=[
URLValidator(schemes=['https']),
],
)
enabled = db_models.BooleanField(default=False)
@property
......
# Generated by Django 2.2.7 on 2020-01-24 13:03
import django.core.validators
from django.db import migrations, models
import feudal.backend.auth.v1.models
class Migration(migrations.Migration):
dependencies = [
('backend', '0011_auto_20200114_1430'),
]
operations = [
migrations.AlterField(
model_name='oidcconfig',
name='issuer_uri',
field=models.CharField(max_length=200, validators=[django.core.validators.URLValidator(schemes=['https'])]),
),
migrations.AlterField(
model_name='oidcconfig',
name='name',
field=models.CharField(max_length=200, validators=[feudal.backend.auth.v1.models.IDPNameValidator()]),
),
]
......@@ -135,7 +135,10 @@ class User(AbstractUser):
if 'sub' not in userinfo:
raise ValueError('Missing attribute in userinfo: sub')
username = '{}@{}'.format(userinfo['sub'], idp.id)
username = '{}@{}'.format(
userinfo['sub'],
idp.name.replace(' ', '_'),
)
if cls.objects.filter(
username=username,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment