| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 4 |
from allauth.socialaccount.providers.fivehundredpx.views import ( |
| 5 |
FiveHundredPxOAuthAdapter, |
| 6 |
) |
| 7 |
from allauth.socialaccount.providers.oauth.provider import OAuthProvider |
| 8 |
|
| 9 |
|
| 10 |
class FiveHundredPxAccount(ProviderAccount): |
| 11 |
def get_profile_url(self): |
| 12 |
return f"https://500px.com/{self.account.extra_data.get('username')}" |
| 13 |
|
| 14 |
def get_avatar_url(self): |
| 15 |
return self.account.extra_data.get("userpic_url") |
| 16 |
|
| 17 |
|
| 18 |
class FiveHundredPxProvider(OAuthProvider): |
| 19 |
id = "500px" |
| 20 |
name = "500px" |
| 21 |
package = "allauth.socialaccount.providers.fivehundredpx" |
| 22 |
account_class = FiveHundredPxAccount |
| 23 |
oauth_adapter_class = FiveHundredPxOAuthAdapter |
| 24 |
|
| 25 |
def get_default_scope(self): |
| 26 |
return [] |
| 27 |
|
| 28 |
def extract_uid(self, data): |
| 29 |
return str(data["id"]) |
| 30 |
|
| 31 |
def extract_common_fields(self, data): |
| 32 |
return dict( |
| 33 |
username=data.get("username"), |
| 34 |
email=data.get("email"), |
| 35 |
first_name=data.get("firstname"), |
| 36 |
last_name=data.get("lastname"), |
| 37 |
) |
| 38 |
|
| 39 |
|
| 40 |
provider_classes = [FiveHundredPxProvider] |