Skip to content
Merged
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
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ or current ones extended):
* Yahoo_ OpenId and OAuth1
* Yammer_ OAuth2
* Yandex_ OAuth1, OAuth2 and OpenId
* Zotero_ OAuth1


User data
Expand Down Expand Up @@ -300,3 +301,4 @@ check `django-social-auth LICENSE`_ for details:
.. _six: http://pythonhosted.org/six/
.. _requests: http://docs.python-requests.org/en/latest/
.. _PixelPin: http://pixelpin.co.uk
.. _Zotero: http://www.zotero.org/
25 changes: 25 additions & 0 deletions docs/backends/zotero.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Zotero
======

Zotero implements OAuth1 as their authentication mechanism for their Web API v3.


1. Go to the `Zotero app registration page`_ to register your application.

2. Fill the **Client ID** and **Client Secret** in your project settings::

SOCIAL_AUTH_ZOTERO_KEY = '...'
SOCIAL_AUTH_ZOTERO_SECRET = '...'

3. Enable the backend::

SOCIAL_AUTH_AUTHENTICATION_BACKENDS = (
...
'social.backends.zotero.ZoteroOAuth',
...
)

Further documentation at `Zotero Web API v3 page`_.

.. _Zotero app registration page: https://www.zotero.org/oauth/apps
.. _Zotero Web API v3 page: https://www.zotero.org/support/dev/web_api/v3/start
31 changes: 31 additions & 0 deletions social/backends/zotero.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Zotero OAuth1 backends, docs at:
http://psa.matiasaguirre.net/docs/backends/zotero.html
"""
from requests import HTTPError

from social.backends.oauth import BaseOAuth2, BaseOAuth1
from social.exceptions import AuthMissingParameter, AuthCanceled
import ipdb
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove this line for Travis CI I guess. Thanks!



class ZoteroOAuth(BaseOAuth1):

"""Zotero OAuth authorization mechanism"""
name = 'zotero'
AUTHORIZATION_URL = 'https://www.zotero.org/oauth/authorize'
REQUEST_TOKEN_URL = 'https://www.zotero.org/oauth/request'
ACCESS_TOKEN_URL = 'https://www.zotero.org/oauth/access'

def get_user_id(self, details, response):
"""
Return user unique id provided by service. For Ubuntu One
the nickname should be original.
"""
return details['userID']

def get_user_details(self, response):
"""Return user details from Zotero API account"""
access_token = response.get('access_token', dict())
return {'username': access_token.get('username', ''),
'userID': access_token.get('userID', '')}
28 changes: 28 additions & 0 deletions social/tests/backends/test_zotero.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import json

from social.p3 import urlencode
from social.tests.backends.oauth import OAuth1Test


class ZoteroOAuth1Test(OAuth1Test):
backend_path = 'social.backends.zotero.ZoteroOAuth'
expected_username = 'FooBar'


access_token_body = json.dumps({
'access_token': {u'oauth_token': u'foobar',
u'oauth_token_secret': u'rodgsNDK4hLJU1504Atk131G',
u'userID': u'123456_abcdef',
u'username': u'anyusername'}})

request_token_body = urlencode({
'oauth_token_secret': 'foobar-secret',
'oauth_token': 'foobar',
'oauth_callback_confirmed': 'true'
})

def test_login(self):
self.do_login()

def test_partial_pipeline(self):
self.do_partial_pipeline()