| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 4 |
from allauth.socialaccount.providers.bitbucket_oauth2.views import ( |
| 5 |
BitbucketOAuth2Adapter, |
| 6 |
) |
| 7 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 8 |
|
| 9 |
|
| 10 |
class BitbucketOAuth2Account(ProviderAccount): |
| 11 |
def get_profile_url(self): |
| 12 |
return self.account.extra_data.get("links", {}).get("html", {}).get("href") |
| 13 |
|
| 14 |
def get_avatar_url(self): |
| 15 |
return self.account.extra_data.get("links", {}).get("avatar", {}).get("href") |
| 16 |
|
| 17 |
|
| 18 |
class BitbucketOAuth2Provider(OAuth2Provider): |
| 19 |
id = "bitbucket_oauth2" |
| 20 |
name = "Bitbucket" |
| 21 |
account_class = BitbucketOAuth2Account |
| 22 |
oauth2_adapter_class = BitbucketOAuth2Adapter |
| 23 |
|
| 24 |
def extract_uid(self, data): |
| 25 |
return data["username"] |
| 26 |
|
| 27 |
def extract_common_fields(self, data): |
| 28 |
return dict( |
| 29 |
email=data.get("email"), |
| 30 |
username=data.get("username"), |
| 31 |
name=data.get("display_name"), |
| 32 |
) |
| 33 |
|
| 34 |
|
| 35 |
provider_classes = [BitbucketOAuth2Provider] |