Skip to content

Commit

Permalink
Merge pull request #116 from stephenmcd/master
Browse files Browse the repository at this point in the history
getpocket.com backend
  • Loading branch information
omab committed Dec 3, 2013
2 parents 07124e7 + f70500a commit cbd1f17
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ or current ones extended):
* OpenId_
* OpenSuse_ OpenId http://en.opensuse.org/openSUSE:Connect
* Orkut_ OAuth1
* Pocket_ OAuth2
* Podio_ OAuth2
* Rdio_ OAuth1 and OAuth2
* Readability_ OAuth1
Expand Down Expand Up @@ -223,6 +224,7 @@ check `django-social-auth LICENSE`_ for details:
.. _Mozilla Persona: http://www.mozilla.org/persona/
.. _Odnoklassniki: http://www.odnoklassniki.ru
.. _Orkut: http://www.orkut.com
.. _Pocket: http://getpocket.com
.. _Podio: https://podio.com
.. _Shopify: http://shopify.com
.. _Skyrock: https://skyrock.com
Expand Down
1 change: 1 addition & 0 deletions docs/backends/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Social backends
mixcloud
odnoklassnikiru
persona
pocket
podio
rdio
readability
Expand Down
12 changes: 12 additions & 0 deletions docs/backends/pocket.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Pocket
======

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/
47 changes: 47 additions & 0 deletions social/backends/pocket.py
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)

0 comments on commit cbd1f17

Please sign in to comment.