Skip to content

Instantly share code, notes, and snippets.

@jmoz
Created November 27, 2012 16:38
Show Gist options
  • Save jmoz/4155334 to your computer and use it in GitHub Desktop.
Save jmoz/4155334 to your computer and use it in GitHub Desktop.
Flask OAuth Twitter
@app.route('/oauth_authorized')
@twitter.authorized_handler
def oauth_authorized(resp):
next_url = request.args.get('next') or url_for('index')
if resp is None:
flash('Authorization denied. Thanks for nothing.', 'error')
return redirect(next_url)
if RedisUser.find(resp['user_id']) is None:
flash('Authorized but unknown user.', 'error')
return redirect(next_url)
session['twitter_token'] = (
resp['oauth_token'],
resp['oauth_token_secret']
)
session['twitter_user'] = (
resp['user_id'],
resp['screen_name']
)
flash('Signed in as %s' % resp['screen_name'], 'success')
return redirect(next_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment