Skip to content

Instantly share code, notes, and snippets.

@lrvick
Created April 26, 2012 06:47
Show Gist options
  • Save lrvick/2496883 to your computer and use it in GitHub Desktop.
Save lrvick/2496883 to your computer and use it in GitHub Desktop.
Github API access with Flask and rauth
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