-
Notifications
You must be signed in to change notification settings - Fork 704
Add heroku button #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3049864
add Procfile
friism 00caefe
add gunicorn to requirements
friism 8ea075b
fix Procfile
friism f1e4cc8
add app.json
friism e5e4f8f
add README section
friism 3660390
fix whitespace
friism d0585c8
shorter name
friism c93495a
generate the redirect url
friism 6d467cf
make it cleaner
friism cb18b04
add sslify
friism 8060cce
update README
friism 29e7b0b
note that both OAuth scopes are required
friism d04e17c
organize imports
friism 1275e27
add docstring for helper method
friism 8188458
better string format
friism 4c903d5
Merge branch 'master' of github.com:uber/Python-Sample-Application in…
friism e62fa12
change scope wording
friism 6a5c1e0
reorganize imports
friism File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: gunicorn app:app --log-file=- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
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) | ||
|
@@ -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) | ||
|
@@ -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' | ||
} | ||
|
@@ -214,6 +218,12 @@ def me(): | |
data=response.text, | ||
) | ||
|
||
def get_redirect_uri(request): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docstring please There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)?