[Python-modules-commits] [python-social-auth] 40/322: Struggling with Khan Academy again...
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 f73ec732ae6153f680e14038b16be511ad2359cb
Author: Anna Warzecha <anna.warzecha at gmail.com>
Date: Tue Nov 18 18:31:33 2014 +0100
Struggling with Khan Academy again...
Conflicts:
social/backends/khanacademy.py
---
social/backends/khanacademy.py | 47 ++++++++++++++++++++++++++++++++++++++++--
1 file changed, 45 insertions(+), 2 deletions(-)
diff --git a/social/backends/khanacademy.py b/social/backends/khanacademy.py
index 17b390c..86fcd7d 100644
--- a/social/backends/khanacademy.py
+++ b/social/backends/khanacademy.py
@@ -3,17 +3,60 @@ Khan Academy OAuth backend, docs at:
http://psa.matiasaguirre.net/docs/backends/facebook.html
"""
+from oauthlib.oauth1 import Client, SIGNATURE_HMAC, SIGNATURE_TYPE_QUERY
from social.backends.oauth import BaseOAuth1
class KhanAcademyOAuth1(BaseOAuth1):
+ """
+ Class used for autorising with Khan Academy.
+
+ Flow of Khan Academy is a bit different than most OAuth 1.0 and consinsts
+ of the following steps:
+ 1. Create signed params to attach to the REQUEST_TOKEN_URL
+ 2. Redirect user to the REQUEST_TOKEN_URL that will respond with
+ oauth_secret, oauth_token, oauth_verifier that should be used with
+ ACCESS_TOKEN_URL
+ 3. Go to ACCESS_TOKEN_URL and grab oauth_token_secret.
+
+ Note that we don't use the AUTHORIZATION_URL.
+
+ AUTHORIZATION_URL requires the following arguments:
+ oauth_consumer_key - Your app's consumer key
+ oauth_nonce - Random 64-bit, unsigned number encoded as an ASCII string
+ in decimal format. The nonce/timestamp pair should always be unique.
+ oauth_version - OAuth version used by your app. Must be "1.0" for now.
+ oauth_signature - String generated using the referenced signature method.
+ oauth_signature_method - Signature algorithm (currently only support
+ "HMAC-SHA1")
+ oauth_timestamp - Integer representing the time the request is sent.
+ The timestamp should be expressed in number of seconds
+ after January 1, 1970 00:00:00 GMT.
+ oauth_callback (optional) - URL to redirect to after request token is
+ received and authorized by the user's chosen identity provider.
+ """
name = 'khanacademy-oauth1'
ID_KEY = 'user_id'
- AUTHORIZATION_URL = 'https://www.khanacademy.org/api/auth'
- REQUEST_TOKEN_URL = 'https://www.khanacademy.org/api/auth/request_token'
+ REQUEST_TOKEN_URL = 'http://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 oauth_authorization_request(self, token):
+ """Generate OAuth request to authorize token."""
+ key, secret = self.get_key_and_secret()
+ state = self.get_or_create_state()
+ auth_client = Client(
+ key, secret,
+ signature_method=SIGNATURE_HMAC,
+ signature_type=SIGNATURE_TYPE_QUERY,
+ callback_uri=self.get_redirect_uri(state)
+ )
+ url, headers, body = auth_client.sign(self.REQUEST_TOKEN_URL)
+ return url
+
+ def get_unauthorized_token(self):
+ return self.strategy.request_data()
+
def get_user_details(self, response):
"""Return user details from Facebook account"""
return {
--
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