Skip to content

Commit

Permalink
Added Doximity Oauth2 provider. (#1512)
Browse files Browse the repository at this point in the history
* 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
rantonov authored and pennersr committed Oct 7, 2016
1 parent 9bcc520 commit 2361391
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Robert Balfre
Roberto Novaes
Rod Xavier Bondoc
Roman Tomjak
Roumen Antonov
Sam Solomon
Seizan Shimazaki
Serafeim Papastefanos
Expand Down
Empty file.
1 change: 1 addition & 0 deletions allauth/socialaccount/providers/doximity/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Create your models here.
39 changes: 39 additions & 0 deletions allauth/socialaccount/providers/doximity/provider.py
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)
62 changes: 62 additions & 0 deletions allauth/socialaccount/providers/doximity/tests.py
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
}
""")
5 changes: 5 additions & 0 deletions allauth/socialaccount/providers/doximity/urls.py
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)
25 changes: 25 additions & 0 deletions allauth/socialaccount/providers/doximity/views.py
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)
2 changes: 2 additions & 0 deletions docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Supported Providers

- Douban (OAuth2)

- Doximity (OAuth2)

- Dropbox (OAuth, OAuth2)

- Edmodo (OAuth2)
Expand Down
16 changes: 14 additions & 2 deletions docs/providers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,24 @@ Bitbucket

App registration (get your key and secret here)
https://bitbucket.org/account/user/{{yourusername}}/oauth-consumers/new

Make sure you select the Account:Read permission.

Development callback URL
http://127.0.0.1:8000/accounts/bitbucket_oauth2/login/callback/

Doximity
--------
Doximity Oauth2 implementation documentation
https://www.doximity.com/developers/documentation#oauth

Request API keys here
https://www.doximity.com/developers/api_signup

Development callback URL
http://localhost:8000/accounts/doximity/login/callback/


Draugiem
--------

Expand Down Expand Up @@ -335,7 +347,7 @@ GitHub

App registration (get your key and secret here)
https://github.com/settings/applications/new

Development callback URL
http://127.0.0.1:8000/accounts/github/login/callback/

Expand Down
1 change: 1 addition & 0 deletions test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
'allauth.socialaccount.providers.bitly',
'allauth.socialaccount.providers.coinbase',
'allauth.socialaccount.providers.douban',
'allauth.socialaccount.providers.doximity',
'allauth.socialaccount.providers.digitalocean',
'allauth.socialaccount.providers.draugiem',
'allauth.socialaccount.providers.dropbox',
Expand Down

0 comments on commit 2361391

Please sign in to comment.