Skip to content

Commit 0c6989e

Browse files
committed
Merge pull request #4 from friism/add-heroku-button
Add heroku button.
2 parents fdb402e + 6a5c1e0 commit 0c6989e

File tree

6 files changed

+42
-7
lines changed

6 files changed

+42
-7
lines changed

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: gunicorn app:app --log-file=-

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ How To Use This
1313
---------------
1414

1515
1. Navigate over to https://developer.uber.com/, and sign up for an Uber developer account.
16-
2. Register a new Uber application and make your Redirect URI http://localhost:7000/submit
16+
2. Register a new Uber application and make your Redirect URI http://localhost:7000/submit - `profile` and `history` OAuth scopes are required
1717
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"'
1818
4. Run ‘pip install -r requirements.txt’ to install dependencies
1919
5. Run ‘python app.py’
@@ -36,6 +36,14 @@ If you want to work on this application we’d love your pull requests and ticke
3636
1. If you open up a ticket, please make sure it describes the problem or feature request fully.
3737
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.
3838

39+
Deploy to Heroku
40+
----------------
41+
42+
Click the buttom below to set up this sample app on Heroku:
43+
44+
[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
45+
46+
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.
3947

4048
Making Requests
4149
---------------

app.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "Uber API Python/Flask sample",
3+
"logo": "http://blogcdn.uber.com/wp-content/uploads/2011/12/New-Logo-Vertical-Dark.jpg",
4+
"repository": "https://github.com/uber/Python-Sample-Application",
5+
"keywords": ["uber", "python", "flask"],
6+
"env": {
7+
"UBER_CLIENT_ID": {
8+
"description": "Your Uber API client id"
9+
},
10+
"UBER_CLIENT_SECRET": {
11+
"description": "Your Uber API client secret"
12+
}
13+
}
14+
}

app.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
from __future__ import absolute_import
2+
3+
import json
4+
import os
5+
from urlparse import urlparse
6+
27
from flask import Flask, render_template, request, redirect, session
8+
from flask_sslify import SSLify
39
from rauth import OAuth2Service
4-
510
import requests
6-
import os
7-
import json
811

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

16+
sslify = SSLify(app)
1317

1418
with open('config.json') as f:
1519
config = json.load(f)
@@ -49,7 +53,7 @@ def signup():
4953
"""
5054
params = {
5155
'response_type': 'code',
52-
'redirect_uri': config.get('redirect_uri'),
56+
'redirect_uri': get_redirect_uri(request),
5357
'scope': config.get('scopes'),
5458
}
5559
url = generate_oauth_service().get_authorize_url(**params)
@@ -64,7 +68,7 @@ def submit():
6468
a code that can be used to obtain an access token for the logged-in use.
6569
"""
6670
params = {
67-
'redirect_uri': config.get('redirect_uri'),
71+
'redirect_uri': get_redirect_uri(request),
6872
'code': request.args.get('code'),
6973
'grant_type': 'authorization_code'
7074
}
@@ -214,6 +218,12 @@ def me():
214218
data=response.text,
215219
)
216220

221+
def get_redirect_uri(request):
222+
"""Returns OAuth redirect URI."""
223+
parsed_url = urlparse(request.url)
224+
if parsed_url.hostname == 'localhost':
225+
return 'http://{hostname}:{port}/submit'.format(hostname=parsed_url.hostname, port=parsed_url.port)
226+
return 'https://{hostname}/submit'.format(hostname=parsed_url.hostname)
217227

218228
if __name__ == '__main__':
219229
app.run(port=7000)

config.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"redirect_uri": "http://localhost:7000/submit",
32
"access_token_url": "https://login.uber.com/oauth/token",
43
"authorize_url": "https://login.uber.com/oauth/authorize",
54
"base_url": "https://login.uber.com/",

requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ nose==1.3.3
99
rauth==0.7.0
1010
requests==2.3.0
1111
wsgiref==0.1.2
12+
13+
gunicorn==18.0
14+
Flask-SSLify==0.1.4

0 commit comments

Comments
 (0)