Create a signal that associates a user with an application

This commit is contained in:
Xeryus Stokkel 2022-01-17 14:14:09 +01:00
parent 7867d49593
commit 490eb6cbff
Signed by: Xeryus Stokkel
GPG Key ID: 7023C2C891DDE681
9 changed files with 33 additions and 0 deletions

View File

3
scim_app/core/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

14
scim_app/core/apps.py Normal file
View File

@ -0,0 +1,14 @@
from django.apps import AppConfig
from django.db.models.signals import post_save
from . import signals
class CoreConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'core'
def ready(self) -> None:
from oauth2_provider.models import get_access_token_model
TokenModel = get_access_token_model()
post_save.connect(signals.set_user_on_application_token, sender=TokenModel)

View File

3
scim_app/core/models.py Normal file
View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

5
scim_app/core/signals.py Normal file
View File

@ -0,0 +1,5 @@
def set_user_on_application_token(sender, **kwargs):
instance = kwargs['instance']
if kwargs['created'] and not instance.user:
instance.user = sender.user.get_queryset().first()
instance.save()

3
scim_app/core/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
scim_app/core/views.py Normal file
View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View File

@ -43,6 +43,8 @@ INSTALLED_APPS = [
'django_scim',
'oauth2_provider',
'core',
]
MIDDLEWARE = [