Skip to content

Commit f70cb3d

Browse files
Cabalistpennersr
authored andcommitted
feat(socialaccount): Add Sharefile provider
1 parent 9492066 commit f70cb3d

File tree

10 files changed

+160
-20
lines changed

10 files changed

+160
-20
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Roberto Novaes
108108
Rod Xavier Bondoc
109109
Roman Tomjak
110110
Roumen Antonov
111+
Ryan Jarvis
111112
Ryan Verner
112113
Sam Solomon
113114
Sanghyeok Lee

allauth/socialaccount/providers/sharefile/__init__.py

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from allauth.socialaccount.providers.base import ProviderAccount
2+
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider
3+
4+
5+
class ShareFileAccount(ProviderAccount):
6+
def to_str(self):
7+
dflt = super(ShareFileAccount, self).to_str()
8+
return self.account.extra_data.get('name', dflt)
9+
10+
11+
class ShareFileProvider(OAuth2Provider):
12+
id = 'sharefile'
13+
name = 'ShareFile'
14+
account_class = ShareFileAccount
15+
16+
def extract_uid(self, data):
17+
return str(data.get('Id', ''))
18+
19+
def extract_common_fields(self, data):
20+
return dict(
21+
email=data.get('Email', ''),
22+
username=data.get('Username', ''),
23+
name=data.get('FullName', ''),
24+
)
25+
26+
27+
provider_classes = [ShareFileProvider]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from allauth.socialaccount.tests import OAuth2TestsMixin
2+
from allauth.tests import MockedResponse, TestCase
3+
4+
from .provider import ShareFileProvider
5+
6+
7+
class ShareFileTests(OAuth2TestsMixin, TestCase):
8+
provider_id = ShareFileProvider.id
9+
10+
def get_mocked_response(self):
11+
return MockedResponse(200, """
12+
{"access_token": "12345678abcdef",
13+
"refresh_token": "12345678abcdef",
14+
"token_type": "bearer",
15+
"expires_in": 28800,
16+
"appcp": "sharefile.com",
17+
"apicp": "sharefile.com",
18+
"subdomain": "example",
19+
"access_files_folders": true,
20+
"modify_files_folders": true,
21+
"admin_users": true,
22+
"admin_accounts": true,
23+
"change_my_settings": true,
24+
"web_app_login": true}
25+
""")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from allauth.socialaccount.providers.oauth2.urls import default_urlpatterns
2+
3+
from .provider import ShareFileProvider
4+
5+
6+
urlpatterns = default_urlpatterns(ShareFileProvider)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import requests
2+
3+
from allauth.socialaccount import app_settings
4+
from allauth.socialaccount.providers.oauth2.views import (
5+
OAuth2Adapter,
6+
OAuth2CallbackView,
7+
OAuth2LoginView,
8+
)
9+
10+
from .provider import ShareFileProvider
11+
12+
13+
class ShareFileOAuth2Adapter(OAuth2Adapter):
14+
provider_id = ShareFileProvider.id
15+
settings = app_settings.PROVIDERS.get(provider_id, {})
16+
subdomain = settings.get('SUBDOMAIN', 'secure')
17+
apicp = settings.get('APICP', 'sharefile.com')
18+
19+
provider_default_url = settings.get('DEFAULT_URL',
20+
'https://secure.sharefile.com')
21+
provider_default_api_url = 'https://{}.sf-api.com'.format(subdomain)
22+
provider_api_version = 'v3'
23+
24+
access_token_url = 'https://{}.{}/oauth/token'.format(subdomain, apicp)
25+
refresh_token_url = 'https://{}.{}/oauth/token'.format(subdomain, apicp)
26+
authorize_url = '{}/oauth/authorize'.format(provider_default_url)
27+
profile_url = '{}/sf/{}/Users'.format(provider_default_api_url,
28+
provider_api_version)
29+
30+
def complete_login(self, request, app, token, response):
31+
headers = {"Authorization": "Bearer {}".format(token.token)}
32+
extra_data = requests.get(self.profile_url, headers=headers).json()
33+
return self.get_provider().sociallogin_from_response(request,
34+
extra_data)
35+
36+
37+
oauth2_login = OAuth2LoginView.adapter_view(ShareFileOAuth2Adapter)
38+
oauth2_callback = OAuth2CallbackView.adapter_view(ShareFileOAuth2Adapter)

docs/installation.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ settings.py (Important - Please note 'django.contrib.sites' is required as INSTA
104104
'allauth.socialaccount.providers.pinterest',
105105
'allauth.socialaccount.providers.reddit',
106106
'allauth.socialaccount.providers.robinhood',
107+
'allauth.socialaccount.providers.sharefile',
107108
'allauth.socialaccount.providers.shopify',
108109
'allauth.socialaccount.providers.slack',
109110
'allauth.socialaccount.providers.soundcloud',

docs/overview.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ Supported Providers
147147

148148
- Salesforce (OAuth2)
149149

150+
- ShareFile (OAuth2)
151+
150152
- Shopify (OAuth2)
151153

152154
- Slack (OAuth2)

docs/providers.rst

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,8 @@ Registering an application:
682682
By default, you will have access to the openid, profile, and offline_access
683683
scopes. With the offline_access scope, the API will provide you with a
684684
refresh token. For additional scopes, see the Globus API docs:
685-
https://docs.globus.org/api/auth/reference/
685+
686+
https://docs.globus.org/api/auth/reference/
686687

687688
.. code-block:: python
688689
@@ -1181,7 +1182,7 @@ SCOPE:
11811182
https://developers.pinterest.com/docs/api/overview/#scopes
11821183

11831184
QuickBooks
1184-
------
1185+
----------
11851186

11861187
App registration (get your key and secret here)
11871188
https://developers.intuit.com/v2/ui#/app/startcreate
@@ -1258,6 +1259,38 @@ To Use:
12581259
- Create a Social application in Django admin, with client id,
12591260
client key, and login_url (in "key" field)
12601261

1262+
ShareFile
1263+
---------
1264+
1265+
The following ShareFile settings are available.
1266+
https://api.sharefile.com/rest/
1267+
1268+
SUBDOMAIN:
1269+
Subdomain of your organization with ShareFile. This is required.
1270+
1271+
Example:
1272+
``test`` for ``https://test.sharefile.com``
1273+
1274+
APICP:
1275+
Defaults to ``secure``. Refer to the ShareFile documentation if you
1276+
need to change this value.
1277+
1278+
DEFAULT_URL:
1279+
Defaults to ``https://secure.sharefile.com`` Refer to the ShareFile
1280+
documentation if you need to change this value.
1281+
1282+
1283+
Example:
1284+
1285+
.. code-block:: python
1286+
1287+
SOCIALACCOUNT_PROVIDERS = {
1288+
'sharefile': {
1289+
'SUBDOMAIN': 'TEST',
1290+
'APICP': 'sharefile.com',
1291+
'DEFAULT_URL': 'https://secure.sharefile.com',
1292+
}
1293+
}
12611294
12621295
Shopify
12631296
-------
@@ -1370,48 +1403,54 @@ Stripe
13701403

13711404
You register your OAUth2 app via the Connect->Settings page of the Stripe
13721405
dashboard:
1373-
https://dashboard.stripe.com/account/applications/settings
1406+
1407+
https://dashboard.stripe.com/account/applications/settings
13741408

13751409
This page will provide you with both a Development and Production `client_id`.
13761410

13771411
You can also register your OAuth2 app callback on the Settings page in the
13781412
"Website URL" box, e.g.:
1379-
http://example.com/accounts/stripe/login/callback/
1413+
1414+
http://example.com/accounts/stripe/login/callback/
13801415

13811416
However, the OAuth2 secret key is not on this page. The secret key is the same
13821417
secret key that you use with the Stripe API generally. This can be found on the
13831418
Stripe dashboard API page:
1384-
https://dashboard.stripe.com/account/apikeys
1419+
1420+
https://dashboard.stripe.com/account/apikeys
13851421

13861422
See more in documentation
1387-
https://stripe.com/docs/connect/standalone-accounts
1423+
https://stripe.com/docs/connect/standalone-accounts
13881424

13891425

13901426
Trello
13911427
------
13921428

13931429
Register the application at
1394-
https://trello.com/app-key
1430+
1431+
https://trello.com/app-key
1432+
13951433
You get one application key per account.
13961434

1397-
Save the "Key" to "Client id", the "Secret" to "Secret Key" and "Key" to the "Key"
1435+
Save the "Key" to "Client id", the "Secret" to "Secret Key" and "Key" to the "Key"
13981436
field.
13991437

1400-
Verify which scope you need at
1401-
https://developers.trello.com/page/authorization
1438+
Verify which scope you need at
1439+
1440+
https://developers.trello.com/page/authorization
1441+
14021442
Need to change the default scope? Add or update the `trello` setting to
14031443
`settings.py`
14041444

1405-
```
1406-
SOCIALACCOUNT_PROVIDERS = {
1407-
'trello': {
1408-
'AUTH_PARAMS': {
1409-
'scope': 'read,write',
1410-
},
1411-
},
1412-
}
1413-
```
1445+
.. code-block:: python
14141446
1447+
SOCIALACCOUNT_PROVIDERS = {
1448+
'trello': {
1449+
'AUTH_PARAMS': {
1450+
'scope': 'read,write',
1451+
},
1452+
},
1453+
}
14151454
14161455
Twitch
14171456
------
@@ -1522,7 +1561,7 @@ Development callback URL
15221561
http://localhost:8000/a
15231562

15241563
Vimeo (OAuth 2)
1525-
-----
1564+
---------------
15261565

15271566
App registration (get your key and secret here)
15281567
https://developer.vimeo.com/apps

test_settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
'allauth.socialaccount.providers.reddit',
115115
'allauth.socialaccount.providers.robinhood',
116116
'allauth.socialaccount.providers.salesforce',
117+
'allauth.socialaccount.providers.sharefile',
117118
'allauth.socialaccount.providers.shopify',
118119
'allauth.socialaccount.providers.slack',
119120
'allauth.socialaccount.providers.soundcloud',

0 commit comments

Comments
 (0)