-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
provider.py
57 lines (45 loc) · 1.59 KB
/
provider.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from allauth.account.models import EmailAddress
from allauth.socialaccount import app_settings
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
class GitHubAccount(ProviderAccount):
def get_profile_url(self):
return self.account.extra_data.get("html_url")
def get_avatar_url(self):
return self.account.extra_data.get("avatar_url")
class GitHubProvider(OAuth2Provider):
id = "github"
name = "GitHub"
account_class = GitHubAccount
oauth2_adapter_class = GitHubOAuth2Adapter
def get_default_scope(self):
scope = []
if app_settings.QUERY_EMAIL:
scope.append("user:email")
return scope
def extract_uid(self, data):
return str(data["id"])
def extract_common_fields(self, data):
return dict(
email=data.get("email"),
username=data.get("login"),
name=data.get("name"),
)
def extract_extra_data(self, data):
if "emails" in data:
data = dict(data)
data.pop("emails")
return data
def extract_email_addresses(self, data):
ret = []
for email in data.get("emails", []):
ret.append(
EmailAddress(
email=email["email"],
primary=email["primary"],
verified=email["verified"],
)
)
return ret
provider_classes = [GitHubProvider]