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
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn app:app --log-file=-
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ How To Use This
---------------

1. Navigate over to https://developer.uber.com/, and sign up for an Uber developer account.
2. Register a new Uber application and make your Redirect URI http://localhost:7000/submit
2. Register a new Uber application and make your Redirect URI http://localhost:7000/submit - `profile` and `history` OAuth scopes are required
3. Fill in the relevant information in the config.json file in the root folder and add your client id and secret as the environment variables UBER_CLIENT_ID AND UBER_CLIENT_SECRET. Run 'export UBER_CLIENT_ID="YOUR_CLIENT_ID"&&export UBER_CLIENT_SECRET="YOUR_CLIENT_SECRET"'
4. Run ‘pip install -r requirements.txt’ to install dependencies
5. Run ‘python app.py’
Expand All @@ -36,6 +36,14 @@ If you want to work on this application we’d love your pull requests and ticke
1. If you open up a ticket, please make sure it describes the problem or feature request fully.
2. If you send us a pull request, make sure you add a test for what you added, and make sure the full test suite runs with nosetests -v.

Deploy to Heroku
----------------

Click the buttom below to set up this sample app on Heroku:

[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)

After creating your app on Heroku, you have to configure the redirect url for your Uber OAuth app. Use a `https://{my-app-name}.herokuapp.com/submit` url.

Making Requests
---------------
Expand Down
14 changes: 14 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Uber API Python/Flask sample",
"logo": "http://blogcdn.uber.com/wp-content/uploads/2011/12/New-Logo-Vertical-Dark.jpg",
"repository": "https://github.com/uber/Python-Sample-Application",
"keywords": ["uber", "python", "flask"],
"env": {
"UBER_CLIENT_ID": {
"description": "Your Uber API client id"
},
"UBER_CLIENT_SECRET": {
"description": "Your Uber API client secret"
}
}
}
20 changes: 15 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
from __future__ import absolute_import

import json
import os
from urlparse import urlparse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

standard lib imports should be on their own block above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the block below (with json and friends)?


from flask import Flask, render_template, request, redirect, session
from flask_sslify import SSLify
from rauth import OAuth2Service

import requests
import os
import json

app = Flask(__name__, static_folder='static', static_url_path='')
app.requests_session = requests.Session()
app.secret_key = os.urandom(24)

sslify = SSLify(app)

with open('config.json') as f:
config = json.load(f)
Expand Down Expand Up @@ -49,7 +53,7 @@ def signup():
"""
params = {
'response_type': 'code',
'redirect_uri': config.get('redirect_uri'),
'redirect_uri': get_redirect_uri(request),
'scope': config.get('scopes'),
}
url = generate_oauth_service().get_authorize_url(**params)
Expand All @@ -64,7 +68,7 @@ def submit():
a code that can be used to obtain an access token for the logged-in use.
"""
params = {
'redirect_uri': config.get('redirect_uri'),
'redirect_uri': get_redirect_uri(request),
'code': request.args.get('code'),
'grant_type': 'authorization_code'
}
Expand Down Expand Up @@ -214,6 +218,12 @@ def me():
data=response.text,
)

def get_redirect_uri(request):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

"""Returns OAuth redirect URI."""
parsed_url = urlparse(request.url)
if parsed_url.hostname == 'localhost':
return 'http://{hostname}:{port}/submit'.format(hostname=parsed_url.hostname, port=parsed_url.port)
return 'https://{hostname}/submit'.format(hostname=parsed_url.hostname)

if __name__ == '__main__':
app.run(port=7000)
1 change: 0 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"redirect_uri": "http://localhost:7000/submit",
"access_token_url": "https://login.uber.com/oauth/token",
"authorize_url": "https://login.uber.com/oauth/authorize",
"base_url": "https://login.uber.com/",
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ nose==1.3.3
rauth==0.7.0
requests==2.3.0
wsgiref==0.1.2

gunicorn==18.0
Flask-SSLify==0.1.4