[Python-modules-commits] [python-social-auth] 15/131: Added Sketchfab OAuth2 backend
Wolfgang Borgert
debacle at moszumanska.debian.org
Sat Dec 24 15:16:56 UTC 2016
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to tag v0.2.20
in repository python-social-auth.
commit 78182009603e37b3af77748687c98c5c2d84b92b
Author: Sylvain Zimmer <sylvain at sylvainzimmer.com>
Date: Fri Apr 15 15:12:16 2016 -0400
Added Sketchfab OAuth2 backend
---
README.rst | 2 ++
docs/backends/index.rst | 1 +
docs/backends/sketchfab.rst | 15 ++++++++++
examples/django_example/example/settings.py | 1 +
examples/django_me_example/example/settings.py | 1 +
social/apps/django_app/tests.py | 1 +
social/backends/sketchfab.py | 38 ++++++++++++++++++++++++++
social/tests/backends/test_sketchfab.py | 26 ++++++++++++++++++
8 files changed, 85 insertions(+)
diff --git a/README.rst b/README.rst
index ec4e25a..87efead 100644
--- a/README.rst
+++ b/README.rst
@@ -108,6 +108,7 @@ or current ones extended):
* Readability_ OAuth1
* Reddit_ OAuth2 https://github.com/reddit/reddit/wiki/OAuth2
* Shopify_ OAuth2
+ * Sketchfab_ OAuth2
* Skyrock_ OAuth1
* Soundcloud_ OAuth2
* Stackoverflow_ OAuth2
@@ -278,6 +279,7 @@ check `django-social-auth LICENSE`_ for details:
.. _Pocket: http://getpocket.com
.. _Podio: https://podio.com
.. _Shopify: http://shopify.com
+.. _Sketchfab: https://sketchfab.com/developers/oauth
.. _Skyrock: https://skyrock.com
.. _Soundcloud: https://soundcloud.com
.. _Stocktwits: https://stocktwits.com
diff --git a/docs/backends/index.rst b/docs/backends/index.rst
index 7e3a235..bb6bdc3 100644
--- a/docs/backends/index.rst
+++ b/docs/backends/index.rst
@@ -120,6 +120,7 @@ Social backends
runkeeper
salesforce
shopify
+ sketchfab
skyrock
slack
soundcloud
diff --git a/docs/backends/sketchfab.rst b/docs/backends/sketchfab.rst
new file mode 100644
index 0000000..cedaa66
--- /dev/null
+++ b/docs/backends/sketchfab.rst
@@ -0,0 +1,15 @@
+Sketchfab
+=========
+
+Sketchfab uses OAuth 2 for authentication.
+
+To use:
+
+- Follow the steps at `Sketchfab Oauth`_
+
+- Fill the ``Client id/key`` and ``Client Secret`` values you received in your django settings::
+
+ SOCIAL_AUTH_SKETCHFAB_KEY = ''
+ SOCIAL_AUTH_SKETCHFAB_SECRET = ''
+
+.. _Sketchfab Oauth: https://sketchfab.com/developers/oauth
\ No newline at end of file
diff --git a/examples/django_example/example/settings.py b/examples/django_example/example/settings.py
index 62f2b5b..9558487 100644
--- a/examples/django_example/example/settings.py
+++ b/examples/django_example/example/settings.py
@@ -174,6 +174,7 @@ AUTHENTICATION_BACKENDS = (
'social.backends.readability.ReadabilityOAuth',
'social.backends.reddit.RedditOAuth2',
'social.backends.runkeeper.RunKeeperOAuth2',
+ 'social.backends.sketchfab.SketchfabOAuth2',
'social.backends.skyrock.SkyrockOAuth',
'social.backends.soundcloud.SoundcloudOAuth2',
'social.backends.spotify.SpotifyOAuth2',
diff --git a/examples/django_me_example/example/settings.py b/examples/django_me_example/example/settings.py
index 7dcdfad..b25968a 100644
--- a/examples/django_me_example/example/settings.py
+++ b/examples/django_me_example/example/settings.py
@@ -173,6 +173,7 @@ AUTHENTICATION_BACKENDS = (
'social.backends.yammer.YammerOAuth2',
'social.backends.stackoverflow.StackoverflowOAuth2',
'social.backends.readability.ReadabilityOAuth',
+ 'social.backends.sketchfab.SketchfabOAuth2',
'social.backends.skyrock.SkyrockOAuth',
'social.backends.tumblr.TumblrOAuth',
'social.backends.reddit.RedditOAuth2',
diff --git a/social/apps/django_app/tests.py b/social/apps/django_app/tests.py
index 022d7fc..1dec95e 100644
--- a/social/apps/django_app/tests.py
+++ b/social/apps/django_app/tests.py
@@ -31,6 +31,7 @@ from social.tests.backends.test_mixcloud import *
from social.tests.backends.test_podio import *
from social.tests.backends.test_readability import *
from social.tests.backends.test_reddit import *
+from social.tests.backends.test_sketchfab import *
from social.tests.backends.test_skyrock import *
from social.tests.backends.test_soundcloud import *
from social.tests.backends.test_stackoverflow import *
diff --git a/social/backends/sketchfab.py b/social/backends/sketchfab.py
new file mode 100644
index 0000000..7614041
--- /dev/null
+++ b/social/backends/sketchfab.py
@@ -0,0 +1,38 @@
+"""
+Sketchfab OAuth2 backend, docs at:
+ http://psa.matiasaguirre.net/docs/backends/sketchfab.html
+ https://sketchfab.com/developers/oauth
+"""
+from social.backends.oauth import BaseOAuth2
+
+
+class SketchfabOAuth2(BaseOAuth2):
+ name = 'sketchfab'
+ ID_KEY = 'uid'
+ AUTHORIZATION_URL = 'https://sketchfab.com/oauth2/authorize/'
+ ACCESS_TOKEN_URL = 'https://sketchfab.com/oauth2/token/'
+ ACCESS_TOKEN_METHOD = 'POST'
+ REDIRECT_STATE = False
+ REQUIRES_EMAIL_VALIDATION = False
+ EXTRA_DATA = [
+ ('username', 'username'),
+ ('apiToken', 'apiToken')
+ ]
+
+ def get_user_details(self, response):
+ """Return user details from Sketchfab account"""
+ user_data = response
+ email = user_data.get('email', '')
+ username = user_data['username']
+ name = user_data.get('displayName', '')
+ fullname, first_name, last_name = self.get_user_names(name)
+ return {'username': username,
+ 'fullname': fullname,
+ 'first_name': first_name,
+ 'last_name': last_name,
+ 'email': email}
+
+ def user_data(self, access_token, *args, **kwargs):
+ """Loads user data from service"""
+ return self.get_json('https://sketchfab.com/v2/users/me',
+ headers={'Authorization': 'Bearer {0}'.format(access_token)})
diff --git a/social/tests/backends/test_sketchfab.py b/social/tests/backends/test_sketchfab.py
new file mode 100644
index 0000000..ada632f
--- /dev/null
+++ b/social/tests/backends/test_sketchfab.py
@@ -0,0 +1,26 @@
+import json
+
+from social.tests.backends.oauth import OAuth2Test
+
+
+class SketchfabOAuth2Test(OAuth2Test):
+ backend_path = 'social.backends.sketchfab.SketchfabOAuth2'
+ user_data_url = 'https://sketchfab.com/v2/users/me'
+ expected_username = 'foobar'
+ access_token_body = json.dumps({
+ 'access_token': 'foobar',
+ 'token_type': 'bearer'
+ })
+ user_data_body = json.dumps({
+ 'uid': '42',
+ 'email': 'foo at bar.com',
+ 'displayName': 'foo bar',
+ 'username': 'foobar',
+ 'apiToken': 'XXX'
+ })
+
+ 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