| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 4 |
from allauth.socialaccount.providers.dingtalk.views import DingTalkOAuth2Adapter |
| 5 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 6 |
|
| 7 |
|
| 8 |
class DingTalkAccount(ProviderAccount): |
| 9 |
def get_avatar_url(self): |
| 10 |
return self.account.extra_data.get("avatarUrl") |
| 11 |
|
| 12 |
def to_str(self): |
| 13 |
return self.account.extra_data.get("nick", super().to_str()) |
| 14 |
|
| 15 |
|
| 16 |
class DingTalkProvider(OAuth2Provider): |
| 17 |
id = "dingtalk" |
| 18 |
name = "DingTalk" |
| 19 |
account_class = DingTalkAccount |
| 20 |
oauth2_adapter_class = DingTalkOAuth2Adapter |
| 21 |
|
| 22 |
def extract_uid(self, data): |
| 23 |
return data["openId"] |
| 24 |
|
| 25 |
def get_default_scope(self): |
| 26 |
return ["openid", "corpid"] |
| 27 |
|
| 28 |
def extract_common_fields(self, data): |
| 29 |
return dict(username=data.get("nick"), name=data.get("nick")) |
| 30 |
|
| 31 |
|
| 32 |
provider_classes = [DingTalkProvider] |