-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add Zotero Backend #514
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
Merged
Merged
Add Zotero Backend #514
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3b99103
Added Zotero OAuth1 backend
9e7373d
Fixed doc line
abbb81a
Merge pull request #1 from mpaolino/zotero-backend
9411c48
Udpated README to include the Zotero backend mention
53f6e92
Merge branch 'master' of github.com:mpaolino/python-social-auth
cb2792c
Added zotero test, work in progress
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 @@ | ||
| 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 |
This file contains hidden or 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,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 | ||
|
|
||
|
|
||
| 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', '')} | ||
This file contains hidden or 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,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() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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!