Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ or current ones extended):
* Tumblr_ OAuth1
* Twilio_ Auth
* Twitter_ OAuth1
* Uber_ OAuth2
* VK.com_ OpenAPI, OAuth2 and OAuth2 for Applications
* Weibo_ OAuth2
* Withings_ OAuth1
Expand Down Expand Up @@ -279,6 +280,7 @@ check `django-social-auth LICENSE`_ for details:
.. _Tripit: https://www.tripit.com
.. _Twilio: https://www.twilio.com
.. _Twitter: http://twitter.com
.. _Uber: http://uber.com
.. _VK.com: http://vk.com
.. _Weibo: https://weibo.com
.. _Wunderlist: https://wunderlist.com
Expand Down
1 change: 1 addition & 0 deletions docs/backends/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Social backends
twilio
twitch
twitter
uber
vend
vimeo
vk
Expand Down
28 changes: 28 additions & 0 deletions docs/backends/uber.rst
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions social/backends/uber.py
Original file line number Diff line number Diff line change
@@ -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
)
}
)
36 changes: 36 additions & 0 deletions social/tests/backends/test_uber.py
Original file line number Diff line number Diff line change
@@ -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@bar.com'

user_data_body = json.dumps({
"first_name": "Foo",
"last_name": "Bar",
"email": "foo@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()