| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.socialaccount.providers.auth0.views import Auth0OAuth2Adapter |
| 4 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 5 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 6 |
|
| 7 |
|
| 8 |
class Auth0Account(ProviderAccount): |
| 9 |
def get_avatar_url(self): |
| 10 |
return self.account.extra_data.get("picture") |
| 11 |
|
| 12 |
|
| 13 |
class Auth0Provider(OAuth2Provider): |
| 14 |
id = "auth0" |
| 15 |
name = "Auth0" |
| 16 |
account_class = Auth0Account |
| 17 |
oauth2_adapter_class = Auth0OAuth2Adapter |
| 18 |
|
| 19 |
def get_default_scope(self): |
| 20 |
return ["openid", "profile", "email"] |
| 21 |
|
| 22 |
def extract_uid(self, data): |
| 23 |
return str(data["sub"]) |
| 24 |
|
| 25 |
def extract_common_fields(self, data): |
| 26 |
return dict( |
| 27 |
email=data.get("email"), |
| 28 |
username=data.get("username"), |
| 29 |
name=data.get("name"), |
| 30 |
) |
| 31 |
|
| 32 |
|
| 33 |
provider_classes = [Auth0Provider] |