I've successfully implemented a baseline Django/pysaml2 integration with SAML assertion using the djangosaml2 package. Users are created dynamically based on a successful authentication which is great! Now I would like to inject a short list of custom attributes into my Django 1.6 "extended" user model.
The djangosaml2 documentation states (see: https://pypi.python.org/pypi/djangosaml2#user-attributes) that I should use the provided Django signal:
...for these cases djangosaml2 provides a Django signal that you can listen to. In order to do so you can add the following code to your app:
from djangosaml2.signals import pre_user_save
def custom_update_user(sender=user, attributes=attributes, user_modified=user_modified)
...
return True # I modified the user object
Here are my questions:
- Where do I place the above signal code?
- How do I tell my extended user model to set an employee id if my extended user model look like this?
models.py
from django.db import models
from django.contrib.auth.models import User
class UserProfile(models.Model):
user = models.OneToOneField(User)
employee_id = models.CharField(blank=True,max_length=150)