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,37 @@
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth.provider import OAuthProvider
class XingAccount(ProviderAccount):
def get_profile_url(self):
return self.account.extra_data.get("permalink")
def get_avatar_url(self):
return self.account.extra_data.get("photo_urls", {}).get("large")
def to_str(self):
dflt = super(XingAccount, self).to_str()
first_name = self.account.extra_data.get("first_name", "")
last_name = self.account.extra_data.get("last_name", "")
name = " ".join([first_name, last_name]).strip()
return name or dflt
class XingProvider(OAuthProvider):
id = "xing"
name = "Xing"
account_class = XingAccount
def extract_uid(self, data):
return data["id"]
def extract_common_fields(self, data):
return dict(
email=data.get("active_email"),
username=data.get("page_name"),
first_name=data.get("first_name"),
last_name=data.get("last_name"),
)
provider_classes = [XingProvider]

View File

@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from allauth.socialaccount.tests import OAuthTestsMixin
from allauth.tests import MockedResponse, TestCase
from .provider import XingProvider
class XingTests(OAuthTestsMixin, TestCase):
provider_id = XingProvider.id
def get_mocked_response(self):
return [
MockedResponse(
200,
"""
{"users":[{"id":"20493333_1cd028","active_email":"raymond.penners@example.com",
"badges":[],"birth_date":{"year":null,"month":null,"day":null},
"business_address":{"street":null,"zip_code":null,"city":null,"province":null,
"country":"NL","email":null,"fax":null,"phone":null,"mobile_phone":null},
"display_name":"Raymond Penners","educational_background":
{"primary_school_id":null,"schools":[],"qualifications":[]},
"employment_status":"EMPLOYEE","first_name":"Raymond","gender":"m",
"haves":null,"instant_messaging_accounts":{},"interests":null,"languages":
{"nl":null},"last_name":"Penners","organisation_member":null,
"page_name":"Raymond_Penners",
"permalink":"https://www.xing.com/profile/Raymond_Penners",
"photo_urls":{"thumb":"https://www.xing.com/img/n/nobody_m.30x40.jpg",
"large":"https://www.xing.com/img/n/nobody_m.140x185.jpg","mini_thumb":
"https://www.xing.com/img/n/nobody_m.18x24.jpg","maxi_thumb":
"https://www.xing.com/img/n/nobody_m.70x93.jpg","medium_thumb":
"https://www.xing.com/img/n/nobody_m.57x75.jpg"},"premium_services":[],
"private_address":{"street":null,"zip_code":null,"city":null,"province":null,
"country":null,"email":"raymond.penners@example.com","fax":null,
"phone":null,"mobile_phone":null},"professional_experience":
{"primary_company":{"name":null,"url":null,"tag":null,"title":null,
"begin_date":null,"end_date":null,"description":null,"industry":"OTHERS",
"company_size":null,"career_level":null},"non_primary_companies":[],
"awards":[]},"time_zone":{"utc_offset":2.0,"name":"Europe/Berlin"},
"wants":null,"web_profiles":{}}]}
""",
)
]

View File

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

View File

@@ -0,0 +1,34 @@
import json
from allauth.socialaccount.providers.oauth.client import OAuth
from allauth.socialaccount.providers.oauth.views import (
OAuthAdapter,
OAuthCallbackView,
OAuthLoginView,
)
from .provider import XingProvider
class XingAPI(OAuth):
url = "https://api.xing.com/v1/users/me.json"
def get_user_info(self):
user = json.loads(self.query(self.url))
return user
class XingOAuthAdapter(OAuthAdapter):
provider_id = XingProvider.id
request_token_url = "https://api.xing.com/v1/request_token"
access_token_url = "https://api.xing.com/v1/access_token"
authorize_url = "https://www.xing.com/v1/authorize"
def complete_login(self, request, app, token, response):
client = XingAPI(request, app.client_id, app.secret, self.request_token_url)
extra_data = client.get_user_info()["users"][0]
return self.get_provider().sociallogin_from_response(request, extra_data)
oauth_login = OAuthLoginView.adapter_view(XingOAuthAdapter)
oauth_callback = OAuthCallbackView.adapter_view(XingOAuthAdapter)