* `Evernote OAuth`_
* `Mail.ru OAuth`_
* `Odnoklassniki OAuth`_
+ * `Mixcloud OAuth2`_
- Basic user data population and signaling, to allows custom fields values
from providers response
'social_auth.backends.contrib.yahoo.YahooOAuthBackend',
'social_auth.backends.OpenIDBackend',
'social_auth.backends.contrib.bitbucket.BitbucketBackend',
+ 'social_auth.backends.contrib.mixcloud.MixcloudBackend',
'social_auth.backends.contrib.live.LiveBackend',
'django.contrib.auth.backends.ModelBackend',
)
SKYROCK_CONSUMER_SECRET = ''
YAHOO_CONSUMER_KEY = ''
YAHOO_CONSUMER_SECRET = ''
+ MIXCLOUD_CLIENT_ID = ''
+ MIXCLOUD_CLIENT_SECRET = ''
- Setup login URLs::
ODNOKLASSNIKI_OAUTH2_APP_KEY = ''
ODNOKLASSNIKI_OAUTH2_CLIENT_SECRET = ''
+Mixcloud OAuth2
+^^^^^^^^^^^^^^^
+
+The `Mixcloud API`_ offers support for authorization.
+To enable OAuth2 support:
+
+- Register a new application at `Mixcloud Developers`_
+
+- Add Mixcloud backend to ``AUTHENTICATION_BACKENDS`` in settings::
+
+ AUTHENTICATION_BACKENDS = (
+ ...
+ 'social_auth.backends.contrib.mixcloud.MixcloudBackend',
+ )
+
+- Fill ``Client Id`` and ``Client Secret`` values in the settings::
+
+ MIXCLOUD_CLIENT_ID = ''
+ MIXCLOUD_CLIENT_SECRET = ''
+
+- Similar to the other OAuth backends you can define::
+
+ MIXCLOUD_EXTRA_DATA = [('username', 'username'), ('name', 'name'), ('pictures', 'pictures'), ('url', 'url')]
+
+as a list of tuples ``(response name, alias)`` to store user profile data on the UserSocialAuth model.
+
Testing
-------
- Evernote support
+- fmoga_ (Florian Moga)
+
+ - Mixcloud support
+
Copyrights
----------
.. _Odnoklassniki OAuth: http://dev.odnoklassniki.ru/wiki/display/ok/The+OAuth+2.0+Protocol
.. _authentication for VKontakte applications: http://www.ikrvss.ru/2011/11/08/django-social-auh-and-vkontakte-application/
.. _Facebook Canvas Application Authentication: http://www.ikrvss.ru/2011/09/22/django-social-auth-and-facebook-canvas-applications/
+.. _Mixcloud OAuth2: http://www.mixcloud.com/developers/documentation/#authorization
+.. _Mixcloud API: http://www.mixcloud.com/developers/documentation
+.. _Mixcloud Developers: http://www.mixcloud.com/developers
+.. _fmoga: https://github.com/fmoga
--- /dev/null
+"""
+Mixcloud OAuth2 support
+"""
+from urllib import urlencode
+from urllib2 import Request, urlopen
+from oauth2 import Request as OAuthRequest
+from django.utils import simplejson
+from social_auth.utils import setting
+from social_auth.backends import OpenIdAuth, ConsumerBasedOAuth, BaseOAuth2, \
+ OAuthBackend, OpenIDBackend, USERNAME
+from social_auth.backends.exceptions import AuthFailed
+from pprint import pprint
+
+MIXCLOUD_PROFILE_URL = 'https://api.mixcloud.com/me/'
+
+class MixcloudBackend(OAuthBackend):
+ name = 'mixcloud'
+
+ def get_user_id(self, details, response):
+ return response['username']
+
+ def get_user_details(self, response):
+ return {USERNAME: response['username'],
+ 'email': None,
+ 'fullname': response['name'],
+ 'first_name': None,
+ 'last_name': None }
+
+class MixcloudOAuth2(BaseOAuth2):
+ AUTH_BACKEND = MixcloudBackend
+ AUTHORIZATION_URL = 'https://www.mixcloud.com/oauth/authorize'
+ ACCESS_TOKEN_URL = 'https://www.mixcloud.com/oauth/access_token'
+ SETTINGS_KEY_NAME = 'MIXCLOUD_CLIENT_ID'
+ SETTINGS_SECRET_NAME = 'MIXCLOUD_CLIENT_SECRET'
+
+ def user_data(self, access_token, *args, **kwargs):
+ return mixcloud_profile(access_token)
+
+def mixcloud_profile(access_token):
+ data = {'access_token': access_token, 'alt': 'json'}
+ request = Request(MIXCLOUD_PROFILE_URL + '?' + urlencode(data))
+ try:
+ return simplejson.loads(urlopen(request).read())
+ except (ValueError, KeyError, IOError):
+ return None
+
+BACKENDS = {
+ 'mixcloud': MixcloudOAuth2,
+}