I have a custom user model:
class Profile(AbstractUser):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
...
telegram_id = models.BigIntegerField(verbose_name='телеграм ID', unique=True, blank=True, null=True)
...
I have configured authorization via Telegram, Google, VK. After authorization via Telegram where do I get extra_data:
{"id": ["123"], "first_name": ["123"], "last_name": ["123"], "username": ["123"], "photo_url": ["https://t.me/i/userpic/320/123"], "auth_date": ["123"], "hash": ["123"]}
An instance Profile and social_auth_usersocialauth records is created.
I want to do the following:
- If the user is new when logging in via Telegram it is checked whether a Profile exists, where
Profile.telegram_id == extra_data["id"] - If such a profile exists: Associate the record social_auth_usersocialauth with this Profile
- If not: Create a record Profile as standard
I have the following social auth pipelines settings:
SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'social_core.pipeline.social_auth.associate_by_email',
'social_core.pipeline.user.create_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',
)
I suppose I need to create my own pipeline where all the logic will take place, but I don't quite understand how to do it correctly so as not to break the logic of other backends.
Ok. I did it.
My pipeline:
It was inserted here:
It works great.