[英]Filtering or restricting Google-Oauth2 login to a set of users in Django using Python Social Auth
[英]python social auth and Django - is there a 1:1 relationship between OAuth users and Django users?
帶有Django的PSA可以正常工作,只是用戶的外觀發生了令人擔憂的變化:
在Twitter OAuth管道處理過程中,我們的系統首先會報告預期的Twitter username
/ uid
(匹配“ id”和“ screen_name”,請參見下面的38200000)。 但是隨后在某個階段( social.pipeline.user.get_username
?),管道函數報告了一個看起來很令人驚訝的用戶,這個用戶對象似乎並不代表Twitter用戶,而是Google用戶。 (請參閱下面的表“ auth_user”中的(2, "person.1")
“ person.1”))。
假設不是在OAuth請求處理期間創建的User對象不是直接從“ social_auth_usersocialauth”支持的模型類中生成的,而是最終從“ auth_user”支持的模型類中生成的(通過外鍵)是否正確? 創建用戶時表如何關聯? 搜索PSA的腸子,我發現了這個
return cls.objects.select_related('user').get(provider=provider,
uid=uid)
在social.apps.django_app.default.models.UserSocialAuth
。 與下面列出的表一致,我猜測這可能表示: "social_auth_usersocialauth"."user_id"
是非唯一的外鍵,PSA在下面的"auth_user"
中找到了(2, "auth_user"
。 因此,我們獲得了提供者Google(而非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
請注意,第一個表的user_id
列中2
出現兩次。
如果默認情況下(OAuth用戶):((Django用戶))關系不是 1:1,是否有辦法將其設為1:1? 還是我們的表損壞了? (PSA 0.2.12)
有兩個模型User(Django user)
和User social auth
,並且關系為1:N,這意味着每個User
可以連接多個社交帳戶。 因此將其設為1:1是沒有意義的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.