| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.account.models import EmailAddress |
| 4 |
from allauth.socialaccount.app_settings import QUERY_EMAIL |
| 5 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 6 |
from allauth.socialaccount.providers.disqus.views import DisqusOAuth2Adapter |
| 7 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 8 |
|
| 9 |
|
| 10 |
class DisqusAccount(ProviderAccount): |
| 11 |
def get_profile_url(self): |
| 12 |
return self.account.extra_data.get("profileUrl") |
| 13 |
|
| 14 |
def get_avatar_url(self): |
| 15 |
return self.account.extra_data.get("avatar", {}).get("permalink") |
| 16 |
|
| 17 |
|
| 18 |
class DisqusProvider(OAuth2Provider): |
| 19 |
id = "disqus" |
| 20 |
name = "Disqus" |
| 21 |
account_class = DisqusAccount |
| 22 |
oauth2_adapter_class = DisqusOAuth2Adapter |
| 23 |
|
| 24 |
def get_default_scope(self): |
| 25 |
scope = ["read"] |
| 26 |
if QUERY_EMAIL: |
| 27 |
scope += ["email"] |
| 28 |
return scope |
| 29 |
|
| 30 |
def extract_uid(self, data): |
| 31 |
return str(data["id"]) |
| 32 |
|
| 33 |
def extract_common_fields(self, data): |
| 34 |
return { |
| 35 |
"username": data.get("username"), |
| 36 |
"email": data.get("email"), |
| 37 |
"name": data.get("name"), |
| 38 |
} |
| 39 |
|
| 40 |
def extract_email_addresses(self, data): |
| 41 |
ret = [] |
| 42 |
email = data.get("email") |
| 43 |
if email: |
| 44 |
ret.append(EmailAddress(email=email, verified=True, primary=True)) |
| 45 |
return ret |
| 46 |
|
| 47 |
|
| 48 |
provider_classes = [DisqusProvider] |