-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
63 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 +1 @@ | ||
web: gunicorn hello:app | ||
web: gunicorn bitly_oauth:app |
This file contains 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,25 @@ | ||
# Bitly Oauth Python (Flask) Example | ||
|
||
|
||
## Setup on bitly | ||
|
||
Go to http://bitly.com/a/oauth_apps and follow the steps to register a new application. | ||
|
||
Make sure to use your Client ID and Client Secret in index.html.erb and welcome_controller.rb. | ||
|
||
|
||
## The files | ||
This example is modeled after [bitly-oauth-rails](https://github.com/kingink/bitly-oauth-rails) | ||
|
||
[templates/welcome.html](https://github.com/kingink/bitly-oauth-flask/blob/sanitize/templates/welcome.html) - Simple link that starts the authentication process. This will take the user to a bitly login page. | ||
|
||
[bitly_oauth.py](https://github.com/kingink/bitly-oauth-flask/blob/sanitize/bitly_oauth.py) - This is were the meat is. After the user logs in they will be redirected back here for more of the oauth process and to get the user access token. | ||
|
||
[templates/oauth.html](https://github.com/kingink/bitly-oauth-flask/blob/sanitize/templates/oauth.html) - Access_token and Login will show on this page. | ||
|
||
|
||
##Links | ||
|
||
[bitly Developer Website](http://dev.bitly.com/) | ||
|
||
[More on bitly Authentication](http://dev.bitly.com/authentication.html) |
This file contains 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,32 @@ | ||
import os | ||
import requests | ||
from flask import Flask | ||
from flask import render_template | ||
from flask import request | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/') | ||
def welcome(): | ||
return render_template('welcome.html') | ||
|
||
@app.route('/oauth/') | ||
def oauth(): | ||
code = request.args.get('code') | ||
client_id = 'YOUR_CLIENT_ID' | ||
client_secret = 'YOUR_CLIENT_SECRET' | ||
redirect_uri = 'YOUR_REDIRECT_URI' | ||
|
||
payload = {'client_id': client_id, 'client_secret': client_secret, 'redirect_uri': redirect_uri, 'code': code} | ||
r = requests.post("https://api-ssl.bitly.com/oauth/access_token", data=payload) | ||
|
||
data = {} | ||
pairs = r.text.split('&') | ||
for pair in pairs: | ||
k, v = pair.split('=') | ||
data[k] = v | ||
|
||
return render_template('oauth.html', login=data['login'], access_token=data['access_token']) | ||
|
||
if __name__ == '__main__': | ||
app.run() |
This file contains 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 |
---|---|---|
|
@@ -5,4 +5,5 @@ Werkzeug==0.9.1 | |
distribute==0.6.34 | ||
gunicorn==0.17.4 | ||
itsdangerous==0.21 | ||
requests==1.2.3 | ||
wsgiref==0.1.2 |
This file contains 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,3 @@ | ||
login: {{ login }} | ||
<br /> | ||
access_token: {{ access_token }} |
This file contains 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 @@ | ||
<a href="https://bitly.com/oauth/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URI">click here to authorize using your bitly account</a> |