| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from django.http import HttpRequest |
| 4 |
|
| 5 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 6 |
from allauth.socialaccount.providers.oauth.provider import OAuthProvider |
| 7 |
from allauth.socialaccount.providers.trello.views import TrelloOAuthAdapter |
| 8 |
|
| 9 |
|
| 10 |
class TrelloAccount(ProviderAccount): |
| 11 |
def get_profile_url(self): |
| 12 |
return None |
| 13 |
|
| 14 |
def get_avatar_url(self): |
| 15 |
return None |
| 16 |
|
| 17 |
|
| 18 |
class TrelloProvider(OAuthProvider): |
| 19 |
id = "trello" |
| 20 |
name = "Trello" |
| 21 |
account_class = TrelloAccount |
| 22 |
oauth_adapter_class = TrelloOAuthAdapter |
| 23 |
|
| 24 |
def get_default_scope(self): |
| 25 |
return ["read"] |
| 26 |
|
| 27 |
def extract_uid(self, data): |
| 28 |
return data["id"] |
| 29 |
|
| 30 |
def extract_common_fields(self, data): |
| 31 |
return dict( |
| 32 |
email=data.get("email"), |
| 33 |
username=data.get("username"), |
| 34 |
name=data.get("name"), |
| 35 |
) |
| 36 |
|
| 37 |
def get_auth_params_from_request(self, request: HttpRequest, action): |
| 38 |
data = super().get_auth_params_from_request(request, action) |
| 39 |
data["type"] = "web_server" |
| 40 |
data["name"] = self.app.name |
| 41 |
# define here for how long it will be, this can be configured on the |
| 42 |
# social app |
| 43 |
data["expiration"] = "never" |
| 44 |
return data |
| 45 |
|
| 46 |
|
| 47 |
provider_classes = [TrelloProvider] |