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,27 @@
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
class ShareFileAccount(ProviderAccount):
def to_str(self):
dflt = super(ShareFileAccount, self).to_str()
return self.account.extra_data.get("name", dflt)
class ShareFileProvider(OAuth2Provider):
id = "sharefile"
name = "ShareFile"
account_class = ShareFileAccount
def extract_uid(self, data):
return str(data.get("Id", ""))
def extract_common_fields(self, data):
return dict(
email=data.get("Email", ""),
username=data.get("Username", ""),
name=data.get("FullName", ""),
)
provider_classes = [ShareFileProvider]

View File

@@ -0,0 +1,28 @@
from allauth.socialaccount.tests import OAuth2TestsMixin
from allauth.tests import MockedResponse, TestCase
from .provider import ShareFileProvider
class ShareFileTests(OAuth2TestsMixin, TestCase):
provider_id = ShareFileProvider.id
def get_mocked_response(self):
return MockedResponse(
200,
"""
{"access_token": "12345678abcdef",
"refresh_token": "12345678abcdef",
"token_type": "bearer",
"expires_in": 28800,
"appcp": "sharefile.com",
"apicp": "sharefile.com",
"subdomain": "example",
"access_files_folders": true,
"modify_files_folders": true,
"admin_users": true,
"admin_accounts": true,
"change_my_settings": true,
"web_app_login": true}
""",
)

View File

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

View File

@@ -0,0 +1,37 @@
import requests
from allauth.socialaccount import app_settings
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
OAuth2CallbackView,
OAuth2LoginView,
)
from .provider import ShareFileProvider
class ShareFileOAuth2Adapter(OAuth2Adapter):
provider_id = ShareFileProvider.id
settings = app_settings.PROVIDERS.get(provider_id, {})
subdomain = settings.get("SUBDOMAIN", "secure")
apicp = settings.get("APICP", "sharefile.com")
provider_default_url = settings.get("DEFAULT_URL", "https://secure.sharefile.com")
provider_default_api_url = "https://{}.sf-api.com".format(subdomain)
provider_api_version = "v3"
access_token_url = "https://{}.{}/oauth/token".format(subdomain, apicp)
refresh_token_url = "https://{}.{}/oauth/token".format(subdomain, apicp)
authorize_url = "{}/oauth/authorize".format(provider_default_url)
profile_url = "{}/sf/{}/Users".format(
provider_default_api_url, provider_api_version
)
def complete_login(self, request, app, token, response):
headers = {"Authorization": "Bearer {}".format(token.token)}
extra_data = requests.get(self.profile_url, headers=headers).json()
return self.get_provider().sociallogin_from_response(request, extra_data)
oauth2_login = OAuth2LoginView.adapter_view(ShareFileOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(ShareFileOAuth2Adapter)