0

PSA with Django, works as expected except for an apparent, and worrisome change of users:

During Twitter OAuth pipeline processing, our system at first reports the expected Twitter username/uid (matching "id" and "screen_name", cf. 38200000 below). But then at some stage (social.pipeline.user.get_username?) a pipeline function reports a user that seems rather surprising, a user object that does not seem to represent the Twitter user, but a Google user. (See (2, "person.1") in table "auth_user" below).

Is it correct to assume that the User object that is made during OAuth request processing is not produced directly form the "social_auth_usersocialauth" backed model class, but eventually from the "auth_user" backed one (via foreign key)? How are the tables related when users are created? Searching the bowels of PSA, I found this

    return cls.objects.select_related('user').get(provider=provider,
                                                  uid=uid)

in social.apps.django_app.default.models.UserSocialAuth. Consistent with the tables listed below, I'm guessing that this could mean: "social_auth_usersocialauth"."user_id" being a non-unique foreign key, PSA finds (2, "person.1") in "auth_user" below. Therefore, we get a user object for provider Google, not Twitter.

sqlite> SELECT id, user_id, provider, uid FROM social_auth_usersocialauth
;
1|2|google-oauth2|email.1@googlemail.com
2|3|google-oauth2|fst.lst@gmail.com
3|2|twitter|382000000

sqlite> SELECT id, username, email FROM auth_user
;
1|foo-bar|technique@somewhere.de
2|person.1|email.1@googlemail.com
3|fst.lst|fst.lst@gmail.com

Note that 2 occurs twice in the user_id column of the first table.

If the relation (OAuth User):(Django user) is not 1:1 by default, is there a way we can make it 1:1? Or have our tables become corrupted or some such? (PSA 0.2.12)

M.javid
  • 6,387
  • 3
  • 41
  • 56
B98
  • 1,229
  • 12
  • 20

1 Answers1

0

There are two models User(Django user) and User social auth, and the relationship is 1:N, means each User can connect with more than one social accounts. So it doesn't make sense to make it 1:1.

Yuwen Yan
  • 4,777
  • 10
  • 33
  • 63
  • We have now found a way to learn which social account was used (e.g. in the pipeline). Do you mean that it doesn't make sense to make the relationship 1:1 on the PSA side (o.K.) or in general? Is PSA's 1:N choice documented somewhere? I only found "Multiple social accounts _can_ be associated to a single user." in [README.rst](https://github.com/omab/python-social-auth/blob/master/README.rst) – B98 Sep 07 '15 at 13:01