[Python-modules-commits] [python-social-auth] 37/322: Basic Khan Academy support

Wolfgang Borgert debacle at moszumanska.debian.org
Sat Dec 24 15:12:46 UTC 2016


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to tag v0.2.10
in repository python-social-auth.

commit 751853dd67ba14f8163721d7b28c24d3c227c77a
Author: Anna Warzecha <anna.warzecha at gmail.com>
Date:   Sun Nov 16 16:25:15 2014 +0100

    Basic Khan Academy support
---
 README.rst                                |  1 +
 social/backends/khanacademy.py            | 31 +++++++++++++++++++++++++++++++
 social/tests/backends/test_khanacademy.py | 30 ++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+)

diff --git a/README.rst b/README.rst
index fadf0cb..71e8922 100644
--- a/README.rst
+++ b/README.rst
@@ -78,6 +78,7 @@ or current ones extended):
     * Instagram_ OAuth2
     * Jawbone_ OAuth2 https://jawbone.com/up/developer/authentication
     * Kakao_ OAuth2 https://developer.kakao.com
+    * `Khan Academy`_ OAuth1 https://github.com/Khan/khan-api/wiki/Khan-Academy-API-Authentication
     * Linkedin_ OAuth1
     * Live_ OAuth2
     * Livejournal_ OpenId
diff --git a/social/backends/khanacademy.py b/social/backends/khanacademy.py
new file mode 100644
index 0000000..1c5dd03
--- /dev/null
+++ b/social/backends/khanacademy.py
@@ -0,0 +1,31 @@
+"""
+Khan Academy OAuth backend, docs at:
+    http://psa.matiasaguirre.net/docs/backends/facebook.html
+"""
+
+from social.backends.oauth import BaseOAuth1
+
+
+class KhanAcademyOAuth1(BaseOAuth1):
+    name = 'khanacademy-oauth'
+    ID_KEY = 'user_id'
+    AUTHORIZATION_URL = 'https://www.khanacademy.org/api/auth'
+    REQUEST_TOKEN_URL = 'https://www.khanacademy.org/api/auth/request_token'
+    ACCESS_TOKEN_URL = 'https://www.khanacademy.org/api/auth/access_token'
+    REDIRECT_URI_PARAMETER_NAME = 'oauth_callback'
+
+    def get_user_details(self, response):
+        """Return user details from Facebook account"""
+        return {
+            'username': response.get('key_email'),
+            'email': response.get('key_email'),
+            'fullname': '',
+            'first_name': '',
+            'last_name': '',
+            'user_id': response.get('user_id')
+        }
+
+    def user_data(self, access_token, *args, **kwargs):
+        """Loads user data from service"""
+        return self.get_json('https://www.khanacademy.org/api/v1/user',
+                             auth=self.oauth_auth(access_token))
diff --git a/social/tests/backends/test_khanacademy.py b/social/tests/backends/test_khanacademy.py
new file mode 100644
index 0000000..65481a0
--- /dev/null
+++ b/social/tests/backends/test_khanacademy.py
@@ -0,0 +1,30 @@
+import json
+
+from social.p3 import urlencode
+
+from social.tests.backends.oauth import OAuth1Test
+
+
+class KhanAcademyOAuth2Test(OAuth1Test):
+    backend_path = 'social.backends.khanacademy.KhanAcademyOAuth1'
+    user_data_url = 'https://www.khanacademy.org/api/v1/user'
+    expected_username = 'foo at bar.com'
+    access_token_body = json.dumps({
+        'access_token': 'foobar',
+        'token_type': 'bearer'
+    })
+    request_token_body = urlencode({
+        'oauth_token_secret': 'foobar-secret',
+        'oauth_token': 'foobar',
+        'oauth_callback_confirmed': 'true'
+    })
+    user_data_body = json.dumps({
+        "key_email": "foo at bar.com",
+        "user_id": "http://googleid.khanacademy.org/11111111111111",
+    })
+
+    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