From af3df16b90557e440f9033f7123411711ffabf6a Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 9 Dec 2018 21:05:25 +0100 Subject: [PATCH] core: add uuid to user, use as sub for OpenID --- passbook/api/v1/openid.py | 2 +- passbook/core/migrations/0006_user_uuid.py | 20 ++++++++++++++++++++ passbook/core/models.py | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 passbook/core/migrations/0006_user_uuid.py diff --git a/passbook/api/v1/openid.py b/passbook/api/v1/openid.py index 2d395fb62..59a26d9a4 100644 --- a/passbook/api/v1/openid.py +++ b/passbook/api/v1/openid.py @@ -12,7 +12,7 @@ class OpenIDUserInfoView(ScopedResourceMixin, View): def get(self, request, *args, **kwargs): """Passbook v1 OpenID API""" payload = { - 'sub': request.user.pk, + 'sub': request.user.uuid.int, 'name': request.user.get_full_name(), 'given_name': request.user.first_name, 'family_name': request.user.last_name, diff --git a/passbook/core/migrations/0006_user_uuid.py b/passbook/core/migrations/0006_user_uuid.py new file mode 100644 index 000000000..1c0c0994c --- /dev/null +++ b/passbook/core/migrations/0006_user_uuid.py @@ -0,0 +1,20 @@ +# Generated by Django 2.1.4 on 2018-12-09 17:58 + +import uuid + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('passbook_core', '0005_auto_20181127_1522'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='uuid', + field=models.UUIDField(default=uuid.uuid4, editable=False), + ), + ] diff --git a/passbook/core/models.py b/passbook/core/models.py index b4c9b8309..6e1fd7211 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -1,6 +1,7 @@ """passbook core models""" import re from logging import getLogger +from uuid import uuid4 import reversion from django.contrib.auth.models import AbstractUser @@ -16,6 +17,7 @@ LOGGER = getLogger(__name__) class User(AbstractUser): """Custom User model to allow easier adding o f user-based settings""" + uuid = models.UUIDField(default=uuid4, editable=False) sources = models.ManyToManyField('Source', through='UserSourceConnection') applications = models.ManyToManyField('Application')