[Python-modules-commits] [python-social-auth] 38/61: Add support for Uber OAuth2 - Uber API v1 - Backend UberOAuth2 added - Tests for UberOAuth2 backend added - Docs for backend added
Wolfgang Borgert
debacle at moszumanska.debian.org
Sat Dec 24 15:14:05 UTC 2016
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to tag v0.2.13
in repository python-social-auth.
commit 93e0cd8b929cc8e830dd7110a204aeaefba7a3a2
Author: Henoc Díaz <henocdz at gmail.com>
Date: Mon Aug 10 00:42:59 2015 -0500
Add support for Uber OAuth2 - Uber API v1
- Backend UberOAuth2 added
- Tests for UberOAuth2 backend added
- Docs for backend added
---
docs/backends/uber.rst | 28 +++++++++++++++++++++++++++
social/backends/uber.py | 39 ++++++++++++++++++++++++++++++++++++++
social/tests/backends/test_uber.py | 36 +++++++++++++++++++++++++++++++++++
3 files changed, 103 insertions(+)
diff --git a/docs/backends/uber.rst b/docs/backends/uber.rst
new file mode 100644
index 0000000..7aca7b9
--- /dev/null
+++ b/docs/backends/uber.rst
@@ -0,0 +1,28 @@
+Uber
+=========
+
+Uber uses OAuth v2 for Authentication.
+
+- Register a new application at the `Uber API`_, and follow the instructions below
+
+OAuth2
+=========
+
+1. Add the Uber OAuth2 backend to your settings page::
+
+ SOCIAL_AUTH_AUTHENTICATION_BACKENDS = (
+ ...
+ 'social.backends.uber.UberOAuth2',
+ ...
+ )
+
+2. Fill ``Client Id`` and ``Client Secret`` values in the settings::
+
+ SOCIAL_AUTH_UBER_KEY = ''
+ SOCIAL_AUTH_UBER_SECRET = ''
+
+3. Scope should be defined by using::
+
+ SOCIAL_AUTH_UBER_SCOPE = ['profile', 'request']
+
+.. _Uber API: https://developer.uber.com/dashboard
diff --git a/social/backends/uber.py b/social/backends/uber.py
new file mode 100644
index 0000000..ef6c381
--- /dev/null
+++ b/social/backends/uber.py
@@ -0,0 +1,39 @@
+"""
+Uber OAuth2 backend, docs at:
+ http://psa.matiasaguirre.net/docs/backends/uber.html
+"""
+from social.backends.oauth import BaseOAuth2
+
+
+class UberOAuth2(BaseOAuth2):
+ name = 'uber'
+ ID_KEY='uuid'
+ SCOPE_SEPARATOR = ' '
+ AUTHORIZATION_URL = 'https://login.uber.com/oauth/authorize'
+ ACCESS_TOKEN_URL = 'https://login.uber.com/oauth/token'
+ ACCESS_TOKEN_METHOD = 'POST'
+
+ def auth_complete_credentials(self):
+ return self.get_key_and_secret()
+
+ def get_user_details(self, response):
+ """Return user details from Uber account"""
+ email = response.get('email', '')
+ fullname, first_name, last_name = self.get_user_names()
+ return {'username': email,
+ 'email': email,
+ 'fullname': fullname,
+ 'first_name': first_name,
+ 'last_name': last_name}
+
+ def user_data(self, access_token, *args, **kwargs):
+ """Loads user data from service"""
+ client_id, client_secret = self.get_key_and_secret()
+ response = kwargs.pop('response')
+
+ return self.get_json('https://api.uber.com/v1/me', headers={
+ 'Authorization': '{0} {1}'.format(
+ response.get('token_type'), access_token
+ )
+ }
+ )
diff --git a/social/tests/backends/test_uber.py b/social/tests/backends/test_uber.py
new file mode 100644
index 0000000..8be3730
--- /dev/null
+++ b/social/tests/backends/test_uber.py
@@ -0,0 +1,36 @@
+import json
+
+from httpretty import HTTPretty
+
+from social.p3 import urlencode
+from social.exceptions import AuthForbidden
+from social.tests.backends.oauth import OAuth1Test, OAuth2Test
+
+
+class UberOAuth2Test(OAuth2Test):
+ user_data_url = 'https://api.uber.com/v1/me'
+ backend_path = 'social.backends.uber.UberOAuth2'
+ expected_username = 'foo at bar.com'
+
+ user_data_body = json.dumps({
+ "first_name": "Foo",
+ "last_name": "Bar",
+ "email": "foo at bar.com",
+ "picture": "https://",
+ "promo_code": "barfoo",
+ "uuid": "91d81273-45c2-4b57-8124-d0165f8240c0"
+ })
+
+ access_token_body = json.dumps({
+ "access_token": "EE1IDxytP04tJ767GbjH7ED9PpGmYvL",
+ "token_type": "Bearer",
+ "expires_in": 2592000,
+ "refresh_token": "Zx8fJ8qdSRRseIVlsGgtgQ4wnZBehr",
+ "scope": "profile history request"
+ })
+
+ 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