| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.account.models import EmailAddress |
| 4 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 5 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 6 |
from allauth.socialaccount.providers.zoho.views import ZohoOAuth2Adapter |
| 7 |
|
| 8 |
|
| 9 |
class ZohoAccount(ProviderAccount): |
| 10 |
pass |
| 11 |
|
| 12 |
|
| 13 |
class ZohoProvider(OAuth2Provider): |
| 14 |
id = "zoho" |
| 15 |
name = "Zoho" |
| 16 |
account_class = ZohoAccount |
| 17 |
oauth2_adapter_class = ZohoOAuth2Adapter |
| 18 |
|
| 19 |
def get_default_scope(self): |
| 20 |
return ["aaaserver.profile.READ"] |
| 21 |
|
| 22 |
def extract_uid(self, data): |
| 23 |
return str(data["ZUID"]) |
| 24 |
|
| 25 |
def extract_common_fields(self, data): |
| 26 |
return dict( |
| 27 |
email=data["Email"], |
| 28 |
username=data["Display_Name"], |
| 29 |
first_name=data["First_Name"], |
| 30 |
last_name=data["Last_Name"], |
| 31 |
) |
| 32 |
|
| 33 |
def extract_email_addresses(self, data): |
| 34 |
ret = [] |
| 35 |
email = data.get("Email") |
| 36 |
if email: |
| 37 |
ret.append( |
| 38 |
EmailAddress( |
| 39 |
email=email, |
| 40 |
verified=False, |
| 41 |
primary=True, |
| 42 |
) |
| 43 |
) |
| 44 |
return ret |
| 45 |
|
| 46 |
|
| 47 |
provider_classes = [ZohoProvider] |