Debian Codegraph @

allauth/socialaccount/providers/lichess/provider.py

raw
1 from __future__ import annotations
2
3 from allauth.account.models import EmailAddress
4 from allauth.socialaccount.app_settings import QUERY_EMAIL
5 from allauth.socialaccount.providers.base import ProviderAccount
6 from allauth.socialaccount.providers.lichess.views import LichessOAuth2Adapter
7 from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
8
9
10 class LichessAccount(ProviderAccount):
11 def get_profile_url(self):
12 return self.account.extra_data.get("url")
13
14 def get_avatar_url(self):
15 return self.account.extra_data.get("avatar")
16
17
18 class LichessProvider(OAuth2Provider):
19 id = "lichess"
20 name = "Lichess"
21 account_class = LichessAccount
22 oauth2_adapter_class = LichessOAuth2Adapter
23 pkce_enabled_default = True
24
25 def extract_uid(self, data):
26 return str(data["id"])
27
28 def extract_common_fields(self, data):
29 first_name = data.get("profile", {}).get("firstName")
30 last_name = data.get("profile", {}).get("lastName")
31
32 return dict(
33 username=data.get("username"),
34 email=data.get("email"),
35 first_name=first_name,
36 last_name=last_name,
37 )
38
39 def extract_email_addresses(self, data):
40 ret = []
41 email = data.get("email")
42
43 if email:
44 ret.append(
45 EmailAddress(
46 email=email,
47 primary=True,
48 )
49 )
50 return ret
51
52 def get_default_scope(self):
53 ret = []
54 if QUERY_EMAIL:
55 ret.append("email:read")
56 return ret
57
58
59 provider_classes = [LichessProvider]