-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from stephenmcd/master
getpocket.com backend
- Loading branch information
Showing
4 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -77,6 +77,7 @@ Social backends | |
mixcloud | ||
odnoklassnikiru | ||
persona | ||
podio | ||
rdio | ||
readability | ||
|
This file contains 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,12 @@ | ||
====== | ||
|
||
Pocket uses a weird variant of OAuth v2 that only defines a consumer key. | ||
|
||
- Register a new application at the `Pocket API`_, and | ||
|
||
- fill ``consumer key`` value in the settings:: | ||
|
||
SOCIAL_AUTH_POCKET_KEY = '' | ||
|
||
.. _Pocket API: http://getpocket.com/developer/ |
This file contains 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,47 @@ | ||
""" | ||
Pocket OAuth2 backend, docs at: | ||
http://psa.matiasaguirre.net/docs/backends/pocket.html | ||
""" | ||
from social.backends.base import BaseAuth | ||
|
||
|
||
class PocketAuth(BaseAuth): | ||
|
||
name = "pocket" | ||
|
||
AUTHORIZATION_URL = 'https://getpocket.com/auth/authorize' | ||
ACCESS_TOKEN_URL = 'https://getpocket.com/v3/oauth/authorize' | ||
REQUEST_TOKEN_URL = 'https://getpocket.com/v3/oauth/request' | ||
ID_KEY = 'username' | ||
|
||
def get_json(self, url, *args, **kwargs): | ||
headers = {'X-Accept': 'application/json'} | ||
kwargs.update({'method': 'POST', 'headers': headers}) | ||
return super(PocketAuth, self).get_json(url, *args, **kwargs) | ||
|
||
def get_user_details(self, response): | ||
return {"username": response["username"]} | ||
|
||
def extra_data(self, user, uid, response, details): | ||
return response | ||
|
||
def auth_url(self): | ||
data = { | ||
'consumer_key': self.setting('POCKET_CONSUMER_KEY'), | ||
'redirect_uri': self.redirect_uri, | ||
} | ||
token = self.get_json(self.REQUEST_TOKEN_URL, data=data)['code'] | ||
self.strategy.session_set('pocket_request_token', token) | ||
bits = (self.AUTHORIZATION_URL, token, self.redirect_uri) | ||
return '%s?request_token=%s&redirect_uri=%s' % bits | ||
|
||
def auth_complete(self, *args, **kwargs): | ||
data = { | ||
'consumer_key': self.setting('POCKET_CONSUMER_KEY'), | ||
'code': self.strategy.session_get('pocket_request_token'), | ||
} | ||
response = self.get_json(self.ACCESS_TOKEN_URL, data=data) | ||
username = response['username'] | ||
access_token = response['access_token'] | ||
kwargs.update({'response': response, 'backend': self}) | ||
return self.strategy.authenticate(*args, **kwargs) |