| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 4 |
from allauth.socialaccount.providers.exist.views import ExistOAuth2Adapter |
| 5 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 6 |
|
| 7 |
|
| 8 |
class ExistAccount(ProviderAccount): |
| 9 |
def get_profile_url(self): |
| 10 |
return "https://exist.io/api/2/accounts/profile/" |
| 11 |
|
| 12 |
def get_avatar_url(self): |
| 13 |
return self.account.extra_data.get("avatar") |
| 14 |
|
| 15 |
|
| 16 |
class ExistProvider(OAuth2Provider): |
| 17 |
id = "exist" |
| 18 |
name = "Exist.io" |
| 19 |
account_class = ExistAccount |
| 20 |
oauth2_adapter_class = ExistOAuth2Adapter |
| 21 |
|
| 22 |
def extract_uid(self, data): |
| 23 |
return data.get("username") |
| 24 |
|
| 25 |
def extract_common_fields(self, data): |
| 26 |
extra_common = super().extract_common_fields(data) |
| 27 |
extra_common.update( |
| 28 |
username=data.get("username"), |
| 29 |
first_name=data.get("first_name"), |
| 30 |
last_name=data.get("last_name"), |
| 31 |
avatar=data.get("avatar"), |
| 32 |
timezone=data.get("timezone"), |
| 33 |
local_time=data.get("local_time"), |
| 34 |
) |
| 35 |
return extra_common |
| 36 |
|
| 37 |
def get_default_scope(self): |
| 38 |
return ["mood_read", "health_read", "productivity_read"] |
| 39 |
|
| 40 |
|
| 41 |
provider_classes = [ExistProvider] |