Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added V2 OAuth2 dropbox Authentification #1018

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/backends/dropbox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,28 @@ Dropbox supports both OAuth 1 and 2.
instructions below for the version of OAuth for which you are adding
support.


OAuth2 Api V2
------

Add the Dropbox OAuth2 backend to your settings page::

SOCIAL_AUTH_AUTHENTICATION_BACKENDS = (
...
'social.backends.dropbox.DropboxOAuth2V2',
...
)

- Fill ``App Key`` and ``App Secret`` values in the settings::

SOCIAL_AUTH_DROPBOX_OAUTH2_KEY = ''
SOCIAL_AUTH_DROPBOX_OAUTH2_SECRET = ''

OAuth1
------

.. deprecated:: V1 api is deprecated.
https://blogs.dropbox.com/developers/2016/06/api-v1-deprecated/
Add the Dropbox OAuth backend to your settings page::

SOCIAL_AUTH_AUTHENTICATION_BACKENDS = (
Expand All @@ -26,6 +45,9 @@ Add the Dropbox OAuth backend to your settings page::
OAuth2
------

.. deprecated:: V1 api is deprecated.
https://blogs.dropbox.com/developers/2016/06/api-v1-deprecated/

Add the Dropbox OAuth2 backend to your settings page::

SOCIAL_AUTH_AUTHENTICATION_BACKENDS = (
Expand Down
38 changes: 38 additions & 0 deletions social/backends/dropbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
http://psa.matiasaguirre.net/docs/backends/dropbox.html
"""
from social.backends.oauth import BaseOAuth1, BaseOAuth2
import warnings


class DropboxOAuth(BaseOAuth1):
Expand All @@ -20,6 +21,12 @@ class DropboxOAuth(BaseOAuth1):
('expires', 'expires')
]

def __init__(self, *args, **kwargs):
warnings.warn(
'Dropbox V1 api is deprecated and will be shute down 2017-06-28 '
'https://blogs.dropbox.com/developers/2016/06/api-v1-deprecated/', DeprecationWarning, stacklevel=2)
super(DropboxOAuth, self).__init__(*args, **kwargs)

def get_user_details(self, response):
"""Return user details from Dropbox account"""
fullname, first_name, last_name = self.get_user_names(
Expand Down Expand Up @@ -48,6 +55,12 @@ class DropboxOAuth2(BaseOAuth2):
('uid', 'username'),
]

def __init__(self, *args, **kwargs):
warnings.warn(
'Dropbox V1 api is deprecated and will be shute down 2017-06-28 '
'https://blogs.dropbox.com/developers/2016/06/api-v1-deprecated/', DeprecationWarning, stacklevel=2)
super(DropboxOAuth2, self).__init__(*args, **kwargs)

def get_user_details(self, response):
"""Return user details from Dropbox account"""
fullname, first_name, last_name = self.get_user_names(
Expand All @@ -65,3 +78,28 @@ def user_data(self, access_token, *args, **kwargs):
'https://api.dropbox.com/1/account/info',
headers={'Authorization': 'Bearer {0}'.format(access_token)}
)

class DropboxOAuth2V2(BaseOAuth2):
name = 'dropbox-oauth2'
ID_KEY = 'uid'
AUTHORIZATION_URL = 'https://www.dropbox.com/oauth2/authorize'
ACCESS_TOKEN_URL = 'https://api.dropboxapi.com/oauth2/token'
ACCESS_TOKEN_METHOD = 'POST'
REDIRECT_STATE = False

def get_user_details(self, response):
"""Return user details from Dropbox account"""
name = response.get('name')
return {'username': str(response.get('account_id')),
'email': response.get('email'),
'fullname': name.get('display_name'),
'first_name': name.get('given_name'),
'last_name': name.get('surname')}

def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
return self.get_json(
'https://api.dropboxapi.com/2/users/get_current_account',
headers={'Authorization': 'Bearer {0}'.format(access_token)},
method='POST'
)