Created
November 27, 2012 16:38
-
-
Save jmoz/4155334 to your computer and use it in GitHub Desktop.
Flask OAuth Twitter
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
@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