This commit is contained in:
Iliyan Angelov
2025-09-14 23:24:25 +03:00
commit c67067a2a4
71311 changed files with 6800714 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
from allauth.socialaccount.app_settings import STORE_TOKENS
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
class EveOnlineAccount(ProviderAccount):
def get_profile_url(self):
return "https://gate.eveonline.com/Profile/{char_name}".format(
char_name=self.account.extra_data.get("CharacterName")
)
def get_avatar_url(self):
return ("https://image.eveonline.com/Character/{char_id}_128.jpg").format(
char_id=self.account.extra_data.get("CharacterID", 1)
)
def to_str(self):
dflt = super(EveOnlineAccount, self).to_str()
return next(
value
for value in (
self.account.extra_data.get("CharacterName", None),
self.account.extra_data.get("CharacterID", None),
dflt,
)
if value is not None
)
class EveOnlineProvider(OAuth2Provider):
id = "eveonline"
name = "EVE Online"
account_class = EveOnlineAccount
def get_default_scope(self):
scopes = []
if STORE_TOKENS:
scopes.append("publicData")
return scopes
def extract_uid(self, data):
return str(data["CharacterOwnerHash"])
def extract_common_fields(self, data):
return dict(name=data.get("CharacterName"))
provider_classes = [EveOnlineProvider]

View File

@@ -0,0 +1,22 @@
from allauth.socialaccount.tests import OAuth2TestsMixin
from allauth.tests import MockedResponse, TestCase
from .provider import EveOnlineProvider
class EveOnlineTests(OAuth2TestsMixin, TestCase):
provider_id = EveOnlineProvider.id
def get_mocked_response(self):
return MockedResponse(
200,
"""
{
"CharacterID": 273042051,
"CharacterName": "CCP illurkall",
"ExpiresOn": "2014-05-23T15:01:15.182864Z",
"Scopes": " ",
"TokenType": "Character",
"CharacterOwnerHash": "XM4D...FoY="
}""",
)

View File

@@ -0,0 +1,6 @@
from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns
from .provider import EveOnlineProvider
urlpatterns = default_urlpatterns(EveOnlineProvider)

View File

@@ -0,0 +1,28 @@
import requests
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
OAuth2CallbackView,
OAuth2LoginView,
)
from .provider import EveOnlineProvider
class EveOnlineOAuth2Adapter(OAuth2Adapter):
provider_id = EveOnlineProvider.id
access_token_url = "https://login.eveonline.com/oauth/token"
authorize_url = "https://login.eveonline.com/oauth/authorize"
profile_url = "https://login.eveonline.com/oauth/verify"
def complete_login(self, request, app, token, **kwargs):
resp = requests.get(
self.profile_url,
headers={"Authorization": "Bearer " + token.token},
)
extra_data = resp.json()
return self.get_provider().sociallogin_from_response(request, extra_data)
oauth2_login = OAuth2LoginView.adapter_view(EveOnlineOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(EveOnlineOAuth2Adapter)