Permalink
Browse files

added disqus

  • Loading branch information...
1 parent 9afedc8 commit af15cf3dc849848c258f2d6677ce8321e7fea040 @NorthIsUp NorthIsUp committed Nov 12, 2012
View
2 README.rst
@@ -32,6 +32,7 @@ credentials. Some features are:
Some contributions added support for:
+ * `DISQUS OAuth`_
* `LiveJournal OpenID`_
* `Orkut OAuth`_
* `Linkedin OAuth`_
@@ -157,6 +158,7 @@ Some bits were derived from others' work and copyrighted by:
.. _myOpenID: https://www.myopenid.com/
.. _Twitter OAuth: http://dev.twitter.com/pages/oauth_faq
.. _Facebook OAuth: http://developers.facebook.com/docs/authentication/
+.. _DISQUS OAuth: http://disqus.com/api/docs/auth/
.. _LiveJournal OpenID: http://www.livejournal.com/support/faqbrowse.bml?faqid=283
.. _Orkut OAuth: http://code.google.com/apis/orkut/docs/rest/developers_guide_protocol.html#Authenticating
.. _Linkedin OAuth: https://www.linkedin.com/secure/developer
View
1 doc/backends/index.rst
@@ -12,6 +12,7 @@ Contents:
angel
bitbucket
browserid
+ disqus
douban
dropbox
evernote
View
15 doc/configuration.rst
@@ -19,6 +19,7 @@ Configuration
'social_auth.backends.yahoo.YahooBackend',
'social_auth.backends.browserid.BrowserIDBackend',
'social_auth.backends.contrib.linkedin.LinkedinBackend',
+ 'social_auth.backends.contrib.disqus.DisqusBackend',
'social_auth.backends.contrib.livejournal.LiveJournalBackend',
'social_auth.backends.contrib.orkut.OrkutBackend',
'social_auth.backends.contrib.foursquare.FoursquareBackend',
@@ -55,12 +56,12 @@ Configuration
FOURSQUARE_CONSUMER_SECRET = ''
VK_APP_ID = ''
VK_API_SECRET = ''
- LIVE_CLIENT_ID = ''
- LIVE_CLIENT_SECRET = ''
- SKYROCK_CONSUMER_KEY = ''
- SKYROCK_CONSUMER_SECRET = ''
- YAHOO_CONSUMER_KEY = ''
- YAHOO_CONSUMER_SECRET = ''
+ LIVE_CLIENT_ID = ''
+ LIVE_CLIENT_SECRET = ''
+ SKYROCK_CONSUMER_KEY = ''
+ SKYROCK_CONSUMER_SECRET = ''
+ YAHOO_CONSUMER_KEY = ''
+ YAHOO_CONSUMER_SECRET = ''
- Setup login URLs::
@@ -271,7 +272,7 @@ Configuration
need some POST data like myOpenID
AuthAlreadyAssociated - A different user has already associated
the social account that the current user
- is trying to associate.
+ is trying to associate.
These are a subclass of ``ValueError`` to keep backward compatibility.
View
4 doc/contributions.rst
@@ -70,6 +70,9 @@ estebistec_ (Steven Cummings)
hepochen_
* Weibo support
+northisup_ (Adam Hitchcock)
+ * DISQUS support
+
.. _caioariede: https://github.com/caioariede
.. _krvss: https://github.com/krvss
.. _jezdez: https://github.com/jezdez
@@ -91,3 +94,4 @@ hepochen_
.. _danielgtaylor: https://github.com/danielgtaylor
.. _estebistec: https://github.com/estebistec
.. _hepochen: https://github.com/hepochen
+.. _northisup: https://github.com/northisup
View
2 doc/intro.rst
@@ -28,6 +28,7 @@ credentials, some features are:
Some contributions added support for:
+ * `DISQUS OAuth`_
* `LiveJournal OpenID`_
* `Orkut OAuth`_
* `Linkedin OAuth`_
@@ -72,6 +73,7 @@ credentials, some features are:
.. _myOpenID: https://www.myopenid.com/
.. _Twitter OAuth: http://dev.twitter.com/pages/oauth_faq
.. _Facebook OAuth: http://developers.facebook.com/docs/authentication/
+.. _DISQUS OAuth: http://disqus.com/api/docs/auth/
.. _LiveJournal OpenID: http://www.livejournal.com/support/faqbrowse.bml?faqid=283
.. _Orkut OAuth: http://code.google.com/apis/orkut/docs/rest/developers_guide_protocol.html#Authenticating
.. _Linkedin OAuth: https://www.linkedin.com/secure/developer
View
1 example/example/settings.py
@@ -126,6 +126,7 @@
'social_auth.backends.contrib.instagram.InstagramBackend',
'social_auth.backends.contrib.github.GithubBackend',
'social_auth.backends.contrib.yandex.YandexBackend',
+ 'social_auth.backends.contrib.disqus.DisqusBackend',
'social_auth.backends.contrib.yahoo.YahooOAuthBackend',
'social_auth.backends.contrib.foursquare.FoursquareBackend',
'social_auth.backends.OpenIDBackend',
View
83 social_auth/backends/contrib/disqus.py
@@ -0,0 +1,83 @@
+from django.utils import simplejson
+from social_auth.backends import BaseOAuth2, OAuthBackend, USERNAME
+from social_auth.utils import dsa_urlopen, backend_setting
+from social_auth.utils import setting
+from urllib import urlencode
+
+
+DISQUS_SERVER = 'disqus.com'
+DISQUS_AUTHORIZATION_URL = 'https://disqus.com/api/oauth/2.0/authorize/'
+DISQUS_ACCESS_TOKEN_URL = 'https://disqus.com/api/oauth/2.0/access_token/'
+DISQUS_CHECK_AUTH = 'https://disqus.com/api/3.0/users/details.json'
+
+
+class DisqusBackend(OAuthBackend):
+ name = 'disqus'
+
+ EXTRA_DATA = [
+ ('avatar', 'avatar'),
+ ('connections', 'connections'),
+ ('user_id', 'user_id'),
+ ('email', 'email'),
+ ('email_hash', 'emailHash'),
+ ('expires', setting('SOCIAL_AUTH_EXPIRATION', 'expires')),
+ ('location', 'location'),
+ ('meta', 'response'),
+ ('name', 'name'),
+ ('username', 'username'),
+ ]
+
+ def get_user_id(self, details, response):
+ return response['response']['id']
+
+ def get_user_details(self, response):
+ """Return user details from Disqus account"""
+ rr = response['response']
+
+ user_id = rr['id']
+ email = rr.get('email', '')
+ full_name = rr.get('name', '')
+ first_name = full_name.split()[0] if full_name else ''
+ last_name = full_name.split()[-1] if full_name else ''
+ username = rr['username']
+
+ return {
+ USERNAME: username,
+ 'user_id': user_id,
+ 'email': email,
+ 'firstname': first_name,
+ 'fullname': full_name,
+ 'lastname': last_name if first_name != last_name else '',
+ }
+
+ def extra_data(self, user, uid, response, details):
+ meta_response = dict(response, **response.get('response', {}))
+ return super(DisqusBackend, self).extra_data(user, uid, meta_response, details)
+
+
+class DisqusAuth(BaseOAuth2):
+ """Disqus OAuth mechanism"""
+ AUTHORIZATION_URL = DISQUS_AUTHORIZATION_URL
+ ACCESS_TOKEN_URL = DISQUS_ACCESS_TOKEN_URL
+ AUTH_BACKEND = DisqusBackend
+ SETTINGS_KEY_NAME = 'DISQUS_CLIENT_ID'
+ SETTINGS_SECRET_NAME = 'DISQUS_CLIENT_SECRET'
+
+ def user_data(self, access_token, *args, **kwargs):
+ """Loads user data from service"""
+ params = {
+ 'access_token': access_token,
+ 'api_key': backend_setting(self, self.SETTINGS_KEY_NAME),
+ 'api_secret': backend_setting(self, self.SETTINGS_SECRET_NAME),
+ }
+ url = DISQUS_CHECK_AUTH + '?' + urlencode(params)
+ try:
+ return simplejson.load(dsa_urlopen(url))
+ except ValueError:
+ return None
+
+
+# Backend definition
+BACKENDS = {
+ 'disqus': DisqusAuth,
+}

0 comments on commit af15cf3

Please sign in to comment.