| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.socialaccount.providers.base import ProviderAccount, ProviderException |
| 4 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 5 |
from allauth.socialaccount.providers.weibo.views import WeiboOAuth2Adapter |
| 6 |
|
| 7 |
|
| 8 |
class WeiboAccount(ProviderAccount): |
| 9 |
def get_profile_url(self): |
| 10 |
# profile_url = "u/3195025850" |
| 11 |
return f"https://www.weibo.com/{self.account.extra_data.get('profile_url')}" |
| 12 |
|
| 13 |
def get_avatar_url(self): |
| 14 |
return self.account.extra_data.get("avatar_large") |
| 15 |
|
| 16 |
|
| 17 |
class WeiboProvider(OAuth2Provider): |
| 18 |
id = "weibo" |
| 19 |
name = "Weibo" |
| 20 |
account_class = WeiboAccount |
| 21 |
oauth2_adapter_class = WeiboOAuth2Adapter |
| 22 |
|
| 23 |
def extract_uid(self, data): |
| 24 |
ret = data.get("idstr") |
| 25 |
if not ret: |
| 26 |
raise ProviderException("Missing 'idstr'") |
| 27 |
return ret |
| 28 |
|
| 29 |
def extract_common_fields(self, data): |
| 30 |
return dict(username=data.get("screen_name"), name=data.get("name")) |
| 31 |
|
| 32 |
|
| 33 |
provider_classes = [WeiboProvider] |