| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.socialaccount.providers.agave.views import AgaveAdapter |
| 4 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 5 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 6 |
|
| 7 |
|
| 8 |
class AgaveAccount(ProviderAccount): |
| 9 |
def get_profile_url(self): |
| 10 |
return self.account.extra_data.get("web_url", "dflt") |
| 11 |
|
| 12 |
def get_avatar_url(self): |
| 13 |
return self.account.extra_data.get("avatar_url", "dflt") |
| 14 |
|
| 15 |
|
| 16 |
class AgaveProvider(OAuth2Provider): |
| 17 |
id = "agave" |
| 18 |
name = "Agave" |
| 19 |
account_class = AgaveAccount |
| 20 |
oauth2_adapter_class = AgaveAdapter |
| 21 |
|
| 22 |
def extract_uid(self, data): |
| 23 |
return str(data.get("create_time")) |
| 24 |
|
| 25 |
def extract_common_fields(self, data): |
| 26 |
return dict( |
| 27 |
email=data.get("email"), |
| 28 |
username=data.get("username", ""), |
| 29 |
name=(f"{data.get('first_name', '')} {data.get('last_name', '')}".strip()), |
| 30 |
) |
| 31 |
|
| 32 |
def get_default_scope(self): |
| 33 |
scope = ["PRODUCTION"] |
| 34 |
return scope |
| 35 |
|
| 36 |
|
| 37 |
provider_classes = [AgaveProvider] |