Debian Codegraph @

allauth/socialaccount/providers/windowslive/provider.py

raw
1 from __future__ import annotations
2
3 from allauth.socialaccount.providers.base import ProviderAccount
4 from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
5 from allauth.socialaccount.providers.windowslive.views import WindowsLiveOAuth2Adapter
6
7
8 class WindowsLiveAccount(ProviderAccount):
9 def to_str(self):
10 email = self.account.extra_data.get("emails", {}).get("preferred")
11 if email:
12 return email
13 return super().to_str()
14
15
16 class WindowsLiveProvider(OAuth2Provider):
17 id = "windowslive"
18 name = "Live"
19 account_class = WindowsLiveAccount
20 oauth2_adapter_class = WindowsLiveOAuth2Adapter
21
22 def get_default_scope(self):
23 return ["wl.basic", "wl.emails"]
24
25 def extract_uid(self, data):
26 return str(data["id"])
27
28 def extract_common_fields(self, data):
29 try:
30 email = data.get("emails").get("preferred")
31 except AttributeError:
32 email = None
33
34 return dict(
35 email=email,
36 last_name=data.get("last_name"),
37 first_name=data.get("first_name"),
38 )
39
40
41 provider_classes = [WindowsLiveProvider]