-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Doximity Oauth2 provider. (#1512)
* Added Doximity Oauth2 provider. Doximity is a professional network for Healthcare professionals in the US. In many ways similar to LinkedIn but with a healthcare focus. * Formatting changes * Formatting changes * Added Doximity to overview.rst
- Loading branch information
Showing
10 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from allauth.socialaccount import providers | ||
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 data[str('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'] | ||
|
||
|
||
providers.registry.register(DoximityProvider) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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@mail.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 | ||
} | ||
""") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns | ||
|
||
from .provider import DoximityProvider | ||
|
||
urlpatterns = default_urlpatterns(DoximityProvider) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import requests | ||
|
||
from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter, | ||
OAuth2LoginView, | ||
OAuth2CallbackView) | ||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters