[Python-modules-commits] [python-social-auth] 301/322: added test cases for AzureADOAuth2 refresh token method added
Wolfgang Borgert
debacle at moszumanska.debian.org
Sat Dec 24 15:13:22 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 b149d29f299f52e9804c3d132f50e8d69555c815
Author: vinhub <vin.bhalerao at gmail.com>
Date: Tue May 12 11:34:33 2015 -0700
added test cases for AzureADOAuth2
refresh token method added
---
social/backends/azuread.py | 17 +++++++++++++++
social/tests/backends/test_azuread.py | 40 +++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+)
diff --git a/social/backends/azuread.py b/social/backends/azuread.py
index 769a0f6..1311139 100644
--- a/social/backends/azuread.py
+++ b/social/backends/azuread.py
@@ -9,6 +9,7 @@ from social.exceptions import AuthException, AuthFailed, AuthCanceled, \
AuthTokenError
from jwt import DecodeError, ExpiredSignature, decode as jwt_decode
from social.backends.oauth import BaseOAuth2
+import requests
import urllib
class AzureADOAuth2(BaseOAuth2):
@@ -76,3 +77,19 @@ class AzureADOAuth2(BaseOAuth2):
data = super(BaseOAuth2, self).extra_data(user, uid, response, details)
data['resource'] = self.setting('RESOURCE')
return data
+
+ def refresh_token_params(self, token, *args, **kwargs):
+ return {
+ 'refresh_token': token,
+ 'grant_type': 'refresh_token',
+ 'resource': self.setting('RESOURCE')
+ }
+
+ def get_auth_token(self, token):
+ response = requests.get('https://graph.windows.net/me', headers={'Authorization': 'Bearer ' + token})
+
+ if response.status_code == 401:
+ new_token_response = self.refresh_token(token)
+ token = new_token_response['access_token']
+
+ return token
diff --git a/social/tests/backends/test_azuread.py b/social/tests/backends/test_azuread.py
new file mode 100644
index 0000000..57df71a
--- /dev/null
+++ b/social/tests/backends/test_azuread.py
@@ -0,0 +1,40 @@
+import json
+from social.p3 import urlencode
+from social.tests.backends.oauth import OAuth2Test
+
+class AzureADOAuth2Test(OAuth2Test):
+
+ backend_path = 'social.backends.azuread.AzureADOAuth2'
+ user_data_url = 'https://graph.windows.net/me'
+ expected_username = 'foobar'
+
+ access_token_body = json.dumps({
+ 'access_token': 'foobar',
+ 'token_type': 'bearer',
+ 'id_token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC83Mjc0MDZhYy03MDY4'
+ 'LTQ4ZmEtOTJiOS1jMmQ2NzIxMWJjNTAvIiwiaWF0IjpudWxsLCJleHAiOm51bGwsImF1ZCI6IjAyOWNjMDEwLWJiNzQtNGQyY'
+ 'i1hMDQwLWY5Y2VkM2ZkMmM3NiIsInN1YiI6InFVOHhrczltSHFuVjZRMzR6aDdTQVpvY2loOUV6cnJJOW1wVlhPSWJWQTgiLC'
+ 'J2ZXIiOiIxLjAiLCJ0aWQiOiI3Mjc0MDZhYy03MDY4LTQ4ZmEtOTJiOS1jMmQ2NzIxMWJjNTAiLCJvaWQiOiI3ZjhlMTk2OS0'
+ '4YjgxLTQzOGMtOGQ0ZS1hZDZmNTYyYjI4YmIiLCJ1cG4iOiJmb29iYXJAdGVzdC5vbm1pY3Jvc29mdC5jb20iLCJnaXZlbl9u'
+ 'YW1lIjoiZm9vIiwiZmFtaWx5X25hbWUiOiJiYXIiLCJuYW1lIjoiZm9vIGJhciIsInVuaXF1ZV9uYW1lIjoiZm9vYmFyQHRlc'
+ '3Qub25taWNyb3NvZnQuY29tIiwicHdkX2V4cCI6IjQ3MzMwOTY4IiwicHdkX3VybCI6Imh0dHBzOi8vcG9ydGFsLm1pY3Jvc2'
+ '9mdG9ubGluZS5jb20vQ2hhbmdlUGFzc3dvcmQuYXNweCJ9.3V50dHXTZOHj9UWtkn2g7BjX5JxNe8skYlK4PdhiLz4'
+ })
+
+ refresh_token_body = json.dumps({
+ 'access_token': 'foobar-new-token',
+ 'token_type': 'bearer',
+ 'expires_in': 3600.0,
+ 'refresh_token': 'foobar-new-refresh-token',
+ 'scope': 'identity'
+ })
+
+ def test_login(self):
+ self.do_login()
+
+ def test_partial_pipeline(self):
+ self.do_partial_pipeline()
+
+ def test_refresh_token(self):
+ user, social = self.do_refresh_token()
+ self.assertEqual(social.extra_data['access_token'], 'foobar-new-token')
\ No newline at end of file
--
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