Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make an abstract verstion of django's UserSocialAuth's model so it can be extended #698

Closed
troygrosfield opened this issue Jul 29, 2015 · 0 comments

Comments

@troygrosfield
Copy link
Contributor

The request here is to make an abstract version of django's UserSocialAuth model so it can be extended:

The current model is great, but when I encounter things like facebook access tokens that expire, I need to store the datetime that the tokens expire so I can query them and extend them. I don't want to store this in the extra_data field because it's stored as a text field and is not queryable. This would allow me to leverage the existing model and just add the extra fields that are needed.

The change for this is super trivial:

class AbstractUserSocialAuth(models.Model, DjangoUserMixin):
    user = models.ForeignKey(USER_MODEL, related_name='social_auth')
    provider = models.CharField(max_length=32)
    uid = models.CharField(max_length=UID_LENGTH)
    extra_data = JSONField()

    def __str__(self):
        return str(self.user)

    class Meta:
        abstract = True

    ...
    The rest of the current UserSocialAuth model
    ...

class UserSocialAuth(AbstractUserSocialAuth):

    class Meta:
        unique_together = ('provider', 'uid')
        db_table = 'social_auth_usersocialauth'

The change is passive for others and lets people leverage the existing work done for the UserSocialAuth model.

Then people can easily create their own versions of the UserSocialAuth model:

class MyUserSocialAuth(AbstractUserSocialAuth):
    token_expires = models.DateTimeField(...)
    last_modified_dttm = models.DateTimeField(...)

    class Meta:
        unique_together = ('provider', 'uid')

@omab, thoughts?

@omab omab closed this as completed in #699 Aug 14, 2015
omab added a commit that referenced this issue Aug 14, 2015
Make an abstract verstion of django's UserSocialAuth's model so it can be extended (fixes #698)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant