| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.socialaccount.providers.amazon.views import AmazonOAuth2Adapter |
| 4 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 5 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 6 |
|
| 7 |
|
| 8 |
class AmazonAccount(ProviderAccount): |
| 9 |
pass |
| 10 |
|
| 11 |
|
| 12 |
class AmazonProvider(OAuth2Provider): |
| 13 |
id = "amazon" |
| 14 |
name = "Amazon" |
| 15 |
account_class = AmazonAccount |
| 16 |
oauth2_adapter_class = AmazonOAuth2Adapter |
| 17 |
|
| 18 |
def get_default_scope(self): |
| 19 |
return ["profile"] |
| 20 |
|
| 21 |
def extract_uid(self, data): |
| 22 |
return str(data["user_id"]) |
| 23 |
|
| 24 |
def extract_common_fields(self, data): |
| 25 |
# Hackish way of splitting the fullname. |
| 26 |
# Assumes no middlenames. |
| 27 |
name = data.get("name", "") |
| 28 |
first_name, last_name = name, "" |
| 29 |
if name and " " in name: |
| 30 |
first_name, last_name = name.split(" ", 1) |
| 31 |
return dict( |
| 32 |
email=data.get("email", ""), last_name=last_name, first_name=first_name |
| 33 |
) |
| 34 |
|
| 35 |
|
| 36 |
provider_classes = [AmazonProvider] |