[Python-modules-commits] [python-social-auth] 26/89: Add a backend for Deezer music service
Wolfgang Borgert
debacle at moszumanska.debian.org
Sat Dec 24 15:15:43 UTC 2016
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to tag v0.2.15
in repository python-social-auth.
commit 57e0d96aa89e27b8f657a09fc6814f7d5316d52d
Author: khamaileon <khamaileon at free.fr>
Date: Tue Feb 16 17:56:51 2016 +0100
Add a backend for Deezer music service
---
docs/backends/index.rst | 1 +
docs/intro.rst | 2 ++
examples/django_example/example/settings.py | 1 +
social/backends/deezer.py | 49 +++++++++++++++++++++++++++++
social/tests/backends/test_deezer.py | 36 +++++++++++++++++++++
5 files changed, 89 insertions(+)
diff --git a/docs/backends/index.rst b/docs/backends/index.rst
index 3d6b7e6..c38b4cc 100644
--- a/docs/backends/index.rst
+++ b/docs/backends/index.rst
@@ -63,6 +63,7 @@ Social backends
coinbase
coursera
dailymotion
+ deezer
digitalocean
disqus
docker
diff --git a/docs/intro.rst b/docs/intro.rst
index b138974..a52d568 100644
--- a/docs/intro.rst
+++ b/docs/intro.rst
@@ -40,6 +40,7 @@ or extend current one):
* Bitbucket_ OAuth1
* Box_ OAuth2
* Dailymotion_ OAuth2
+ * Deezer_ OAuth2
* Disqus_ OAuth2
* Douban_ OAuth1 and OAuth2
* Dropbox_ OAuth1
@@ -120,6 +121,7 @@ section.
.. _Bitbucket: https://bitbucket.org
.. _Box: https://www.box.com
.. _Dailymotion: https://dailymotion.com
+.. _Deezer: https://www.deezer.com
.. _Disqus: https://disqus.com
.. _Douban: http://www.douban.com
.. _Dropbox: https://dropbox.com
diff --git a/examples/django_example/example/settings.py b/examples/django_example/example/settings.py
index 58ab9c7..6e6e98b 100644
--- a/examples/django_example/example/settings.py
+++ b/examples/django_example/example/settings.py
@@ -132,6 +132,7 @@ AUTHENTICATION_BACKENDS = (
'social.backends.coinbase.CoinbaseOAuth2',
'social.backends.coursera.CourseraOAuth2',
'social.backends.dailymotion.DailymotionOAuth2',
+ 'social.backends.deezer.DeezerOAuth2',
'social.backends.disqus.DisqusOAuth2',
'social.backends.douban.DoubanOAuth2',
'social.backends.dropbox.DropboxOAuth',
diff --git a/social/backends/deezer.py b/social/backends/deezer.py
new file mode 100644
index 0000000..c7c18a2
--- /dev/null
+++ b/social/backends/deezer.py
@@ -0,0 +1,49 @@
+"""
+Deezer backend, docs at:
+ https://developers.deezer.com/api/oauth
+ https://developers.deezer.com/api/permissions
+"""
+from urllib.parse import parse_qsl
+
+from social.backends.oauth import BaseOAuth2
+
+
+class DeezerOAuth2(BaseOAuth2):
+ """Deezer OAuth2 authentication backend"""
+ name = 'deezer'
+ ID_KEY = 'name'
+ AUTHORIZATION_URL = 'https://connect.deezer.com/oauth/auth.php'
+ ACCESS_TOKEN_URL = 'https://connect.deezer.com/oauth/access_token.php'
+ ACCESS_TOKEN_METHOD = 'POST'
+ SCOPE_SEPARATOR = ','
+ REDIRECT_STATE = False
+
+ def auth_complete_params(self, state=None):
+ client_id, client_secret = self.get_key_and_secret()
+ return {
+ 'app_id': client_id,
+ 'secret': client_secret,
+ 'code': self.data.get('code')
+ }
+
+ def request_access_token(self, *args, **kwargs):
+ response = self.request(*args, **kwargs)
+ return dict(parse_qsl(response.text))
+
+ def get_user_details(self, response):
+ """Return user details from Deezer account"""
+ fullname, first_name, last_name = self.get_user_names(
+ first_name=response.get('firstname'),
+ last_name=response.get('lastname')
+ )
+ return {'username': response.get('name'),
+ 'email': response.get('email'),
+ 'fullname': fullname,
+ 'first_name': first_name,
+ 'last_name': last_name}
+
+ def user_data(self, access_token, *args, **kwargs):
+ """Loads user data from service"""
+ return self.get_json('http://api.deezer.com/user/me', params={
+ 'access_token': access_token
+ })
diff --git a/social/tests/backends/test_deezer.py b/social/tests/backends/test_deezer.py
new file mode 100644
index 0000000..3c74cae
--- /dev/null
+++ b/social/tests/backends/test_deezer.py
@@ -0,0 +1,36 @@
+import json
+
+from social.tests.backends.oauth import OAuth2Test
+
+
+class DeezerOAuth2Test(OAuth2Test):
+ backend_path = 'social.backends.deezer.DeezerOAuth2'
+ user_data_url = 'http://api.deezer.com/user/me'
+ expected_username = 'foobar'
+ access_token_body = 'access_token=foobar&expires=0'
+ user_data_body = json.dumps({
+ 'id': '1',
+ 'name': 'foobar',
+ 'lastname': '',
+ 'firstname': '',
+ 'status': 0,
+ 'birthday': '1970-01-01',
+ 'inscription_date': '2015-01-01',
+ 'gender': 'M',
+ 'link': 'https://www.deezer.com/profile/1',
+ 'picture': 'https://api.deezer.com/user/1/image',
+ 'picture_small': 'https://cdns-images.dzcdn.net/images/user//56x56-000000-80-0-0.jpg',
+ 'picture_medium': 'https://cdns-images.dzcdn.net/images/user//250x250-000000-80-0-0.jpg',
+ 'picture_big': 'https://cdns-images.dzcdn.net/images/user//500x500-000000-80-0-0.jpg',
+ 'country': 'FR',
+ 'lang': 'FR',
+ 'is_kid': False,
+ 'tracklist': 'https://api.deezer.com/user/1/flow',
+ 'type': 'user'
+ })
+
+ def test_login(self):
+ self.do_login()
+
+ def test_partial_pipeline(self):
+ self.do_partial_pipeline()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-social-auth.git
More information about the Python-modules-commits
mailing list