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,38 @@
from allauth.socialaccount.providers.base import ProviderAccount
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
class DoximityAccount(ProviderAccount):
def get_profile_url(self):
return None
def get_avatar_url(self):
return self.account.extra_data.get("profile_photo")
def to_str(self):
dflt = super(DoximityAccount, self).to_str()
return self.account.extra_data.get("full_name", dflt)
class DoximityProvider(OAuth2Provider):
id = "doximity"
name = "Doximity"
account_class = DoximityAccount
def extract_uid(self, data):
return str(data["id"]) # the Doximity id is long
def extract_common_fields(self, data):
return dict(
username=data.get("email"),
first_name=data.get("firstname"),
last_name=data.get("lastname"),
email=data.get("email"),
name=data.get("full_name"),
)
def get_default_scope(self):
return ["basic", "email"]
provider_classes = [DoximityProvider]

View File

@@ -0,0 +1,65 @@
from allauth.socialaccount.tests import OAuth2TestsMixin
from allauth.tests import MockedResponse, TestCase
from .provider import DoximityProvider
class DoximityTests(OAuth2TestsMixin, TestCase):
provider_id = DoximityProvider.id
def get_mocked_response(self):
return MockedResponse(
200,
"""
{
"id": 41993552342,
"npi": 1952635229,
"firstname": "John",
"middlename": "Henry",
"maiden_name": null,
"lastname": "Smith",
"full_name": "Ahmed S Belal, MD",
"gender": "M",
"city": "San Francisco",
"state": "CA",
"zip": "94107",
"phone": "(650) 200-3901",
"fax": "888-416-8572",
"email": "abelalmd@example.com",
"address_1": "500 3rd St.",
"address_2": "Suite 510",
"lat": 42.3663926,
"lon": -71.051395,
"additional_locations": [{
"address_1": "12 Main st",
"address_2": null,
"city": "Cambridge",
"state": "MA",
"phone": "555-555-5555",
"fax": null,
"zip": "02138"
}],
"credentials": "MD",
"verified": true,
"description": "Chief of Cardiology",
"medical_school": "UCSF School of Medicine",
"residencies": ["Stanford Medical Center", "Mt Sinai Hospital"],
"specialty": "Cardiology",
"specialty_details": {
"abbr": "Cards",
"code": "CA00",
"credential_id": 4,
"name": "Cardiology",
"id": "CA00"
},
"hospitals": [{
"name": "Mills-Peninsula Health Services",
"aha_id": "6930315"
}],
"subspecialties": ["General Cardiology", "Cardiac Disease"],
"profile_photo": "https://s3.amazonaws.com/doximity_prod_uploads\
/profile_photos/7969/normal/profile.png",
"colleague_count": 142
}
""",
)

View File

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

View File

@@ -0,0 +1,26 @@
import requests
from allauth.socialaccount.providers.oauth2.views import (
OAuth2Adapter,
OAuth2CallbackView,
OAuth2LoginView,
)
from .provider import DoximityProvider
class DoximityOAuth2Adapter(OAuth2Adapter):
provider_id = DoximityProvider.id
access_token_url = "https://auth.doximity.com/oauth/token"
authorize_url = "https://auth.doximity.com/oauth/authorize"
profile_url = "https://www.doximity.com/api/v1/users/current"
def complete_login(self, request, app, token, **kwargs):
headers = {"Authorization": "Bearer %s" % token.token}
resp = requests.get(self.profile_url, headers=headers)
extra_data = resp.json()
return self.get_provider().sociallogin_from_response(request, extra_data)
oauth2_login = OAuth2LoginView.adapter_view(DoximityOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(DoximityOAuth2Adapter)