| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 4 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 5 |
from allauth.socialaccount.providers.tumblr_oauth2.views import TumblrOAuth2Adapter |
| 6 |
|
| 7 |
|
| 8 |
class TumblrAccount(ProviderAccount): |
| 9 |
def get_profile_url(self): |
| 10 |
return f"https://{self.account.extra_data.get('name')}.tumblr.com/" |
| 11 |
|
| 12 |
|
| 13 |
class TumblrOAuth2Provider(OAuth2Provider): |
| 14 |
id = "tumblr_oauth2" |
| 15 |
name = "Tumblr" |
| 16 |
account_class = TumblrAccount |
| 17 |
oauth2_adapter_class = TumblrOAuth2Adapter |
| 18 |
|
| 19 |
def extract_uid(self, data): |
| 20 |
return data["name"] |
| 21 |
|
| 22 |
def extract_common_fields(self, data): |
| 23 |
return dict( |
| 24 |
first_name=data.get("name"), |
| 25 |
) |
| 26 |
|
| 27 |
def get_default_scope(self): |
| 28 |
return ["read"] |
| 29 |
|
| 30 |
|
| 31 |
provider_classes = [TumblrOAuth2Provider] |