| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 4 |
from allauth.socialaccount.providers.battlenet.views import BattleNetOAuth2Adapter |
| 5 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 6 |
|
| 7 |
|
| 8 |
class BattleNetAccount(ProviderAccount): |
| 9 |
def to_str(self): |
| 10 |
battletag = self.account.extra_data.get("battletag") |
| 11 |
return battletag or super().to_str() |
| 12 |
|
| 13 |
|
| 14 |
class BattleNetProvider(OAuth2Provider): |
| 15 |
id = "battlenet" |
| 16 |
name = "Battle.net" |
| 17 |
account_class = BattleNetAccount |
| 18 |
oauth2_adapter_class = BattleNetOAuth2Adapter |
| 19 |
|
| 20 |
def extract_uid(self, data): |
| 21 |
uid = str(data["id"]) |
| 22 |
if data.get("region") == "cn": |
| 23 |
# China is on a different account system. UIDs can clash with US. |
| 24 |
return f"{uid}-cn" |
| 25 |
return uid |
| 26 |
|
| 27 |
def extract_common_fields(self, data): |
| 28 |
return {"username": data.get("battletag")} |
| 29 |
|
| 30 |
def get_default_scope(self): |
| 31 |
# Optional scopes: "sc2.profile", "wow.profile" |
| 32 |
return [] |
| 33 |
|
| 34 |
|
| 35 |
provider_classes = [BattleNetProvider] |