Created
April 26, 2012 06:47
-
-
Save lrvick/2496883 to your computer and use it in GitHub Desktop.
Github API access with Flask and rauth
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
from flask import Flask, request, redirect, url_for | |
from rauth.service import OAuth1Service, OAuth2Service | |
github = OAuth2Service( | |
name='github', | |
consumer_key='GITHUB_CONSUMER_KEY', | |
consumer_secret='GITHUB_CONSUMER_SECRET', | |
access_token_url='https://github.com/login/oauth/access_token', | |
authorize_url='https://github.com/login/oauth/authorize', | |
) | |
app = Flask(__name__) | |
app.debug = True | |
@app.route('/') | |
def index(): | |
code = request.args.get('code',None) | |
if code: | |
print 'CODE: ',code | |
access_token = github.get_access_token( | |
code=code, | |
).content['access_token'] | |
# The above does not contain access_token and results in a KeyError | |
print 'ACCESS_TOKEN: ',access_token | |
else: | |
return redirect(url_for('login')) | |
@app.route('/login') | |
def login(): | |
authorize_url = github.get_authorize_url() | |
print authorize_url | |
return redirect(authorize_url) | |
if __name__ == '__main__': | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment