| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 4 |
from allauth.socialaccount.providers.bitly.views import BitlyOAuth2Adapter |
| 5 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 6 |
|
| 7 |
|
| 8 |
class BitlyAccount(ProviderAccount): |
| 9 |
def get_profile_url(self): |
| 10 |
return self.account.extra_data.get("profile_url") |
| 11 |
|
| 12 |
def get_avatar_url(self): |
| 13 |
return self.account.extra_data.get("profile_image") |
| 14 |
|
| 15 |
|
| 16 |
class BitlyProvider(OAuth2Provider): |
| 17 |
id = "bitly" |
| 18 |
name = "Bitly" |
| 19 |
account_class = BitlyAccount |
| 20 |
oauth2_adapter_class = BitlyOAuth2Adapter |
| 21 |
|
| 22 |
def extract_uid(self, data): |
| 23 |
return str(data["login"]) |
| 24 |
|
| 25 |
def extract_common_fields(self, data): |
| 26 |
return dict(username=data["login"], name=data.get("full_name")) |
| 27 |
|
| 28 |
|
| 29 |
provider_classes = [BitlyProvider] |