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,58 @@
import hashlib
from urllib.parse import urlencode
from allauth.account.models import EmailAddress
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
class FrontierAccount(ProviderAccount):
def get_profile_url(self):
return None
def get_avatar_url(self):
return "https://www.gravatar.com/avatar/%s?%s" % (
hashlib.md5(
self.account.extra_data.get("email").lower().encode("utf-8")
).hexdigest(),
urlencode({"d": "mp"}),
)
def to_str(self):
dflt = super(FrontierAccount, self).to_str()
full_name = "%s %s" % (
self.account.extra_data.get("firstname", dflt),
self.account.extra_data.get("lastname", dflt),
)
return full_name
class FrontierProvider(OAuth2Provider):
id = "frontier"
name = "Frontier"
account_class = FrontierAccount
def get_default_scope(self):
scope = ["auth", "capi"]
return scope
def extract_uid(self, data):
return str(data["customer_id"])
def extract_common_fields(self, data):
return dict(
email=data.get("email"),
username=data.get("email"),
last_name=data.get("lastname"),
first_name=data.get("firstname"),
)
def extract_email_addresses(self, data):
ret = []
email = data.get("email")
if email:
ret.append(EmailAddress(email=email, verified=True, primary=True))
return ret
provider_classes = [FrontierProvider]

View File

@@ -0,0 +1,23 @@
from allauth.socialaccount.tests import OAuth2TestsMixin
from allauth.tests import MockedResponse, TestCase
from .provider import FrontierProvider
class FrontierTests(OAuth2TestsMixin, TestCase):
provider_id = FrontierProvider.id
def get_mocked_response(self):
return MockedResponse(
200,
"""
{
"email": "johndoe@example.com",
"customer_id": "1234567",
"firstname": "John",
"developer": false,
"lastname": "Doe",
"allowedDownloads": ["FORC-FDEV-D-1010", "FORC-FDEV-D-1012", "COMBAT_TUTORIAL_DEMO", "FORC-FDEV-D-1013", "PUBLIC_TEST_SERVER", "FORC_FDEV_V_ADDER_LRPO", "FORC_FDEV_V_CHALLENGER_LRPO", "FORC_FDEV_V_CHIEFTAIN_LRPO", "FORC_FDEV_V_CRUSADER_LRPO", "FORC_FDEV_V_ANACONDA_LRPO", "FORC_FDEV_V_ASP_LRPO", "FORC_FDEV_V_ASP_SCOUT_LRPO", "FORC_FDEV_V_BELUGA_LRPO", "FORC_FDEV_V_COBRA_MKIII_LRPO", "FORC_FDEV_V_DIAMOND_EXPLORER_LRPO", "FORC_FDEV_V_COBRA_MKIV_LRPO", "FORC_FDEV_V_DIAMOND_SCOUT_LRPO", "FORC_FDEV_V_DOLPHIN_LRPO", "FORC_FDEV_V_EAGLE_LRPO", "FORC_FDEV_V_FEDERAL_ASSAULT_LRPO", "FORC_FDEV_V_FEDERAL_CORVETTE_LRPO", "FORC_FDEV_V_FEDDROP_LRPO", "FORC_FDEV_V_FEDERAL_FIGHTER_LRPO", "FORC_FDEV_V_FEDERAL_GUNSHIP_LRPO", "FORC_FDEV_V_FERDELANCE_LRPO", "FORC_FDEV_V_HAULER_LRPO", "FORC_FDEV_V_CLIPPER_LRPO", "FORC_FDEV_V_IMPERIAL_COURIER_LRPO", "FORC_FDEV_V_IMPERIAL_CUTTER_LRPO", "FORC_FDEV_V_IMPERIAL_EAGLE_LRPO", "FORC_FDEV_V_IMPERIAL_FIGHTER_LRPO", "FORC_FDEV_V_KEELBACK_LRPO", "FORC_FDEV_V_KRAIT_LRPO", "FORC_FDEV_V_KRAIT_LITE_LRPO", "FORC_FDEV_V_MAMBA_LRPO", "FORC_FDEV_V_ORCA_LRPO", "FORC_FDEV_V_PYTHON_LRPO", "FORC_FDEV_V_SIDEWINDER_LRPO", "FORC_FDEV_V_TAIPAN_LRPO", "FORC_FDEV_V_MAMMOTH_LRPO", "FORC_FDEV_V_TYPE6_LRPO", "FORC_FDEV_V_TYPE7_LRPO", "FORC_FDEV_V_TYPE9_LRPO", "FORC_FDEV_V_VIPER_MKIII_LRPO", "FORC_FDEV_V_VIPER_MKIV_LRPO", "FORC_FDEV_V_VULTURE_LRPO", "FORC-FDEV-D-1022", "FORC_FDEV_V_DECAL_1091", "FORC_FDEV_V_DECAL_1100", "FORC_FDEV_V_DECAL_1149", "FORC_FDEV_V_DECAL_1150", "FORC_FDEV_V_DECAL_1151", "FORC_FDEV_V_DECAL_1176", "FORC_FDEV_V_DECAL_1177", "FORC-FDEV-DO-1000", "FORC-FDEV-DO-1003", "FORC-FDEV-DO-1006", "PUBLIC_TEST_SERVER_OD"],
"platform": "frontier"
}""",
)

View File

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

View File

@@ -0,0 +1,30 @@
import requests
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
OAuth2CallbackView,
OAuth2LoginView,
)
from .provider import FrontierProvider
class FrontierOAuth2Adapter(OAuth2Adapter):
provider_id = FrontierProvider.id
AUTH_API = "https://auth.frontierstore.net"
access_token_url = AUTH_API + "/token"
authorize_url = AUTH_API + "/auth"
profile_url = AUTH_API + "/me"
def complete_login(self, request, app, token, **kwargs):
resp = requests.get(
self.profile_url,
headers={"Authorization": "Bearer " + token.token},
)
resp.raise_for_status()
extra_data = resp.json()
return self.get_provider().sociallogin_from_response(request, extra_data)
oauth2_login = OAuth2LoginView.adapter_view(FrontierOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(FrontierOAuth2Adapter)