Book Image

Flask Framework Cookbook

By : Shalabh Aggarwal
Book Image

Flask Framework Cookbook

By: Shalabh Aggarwal

Overview of this book

Table of Contents (19 chapters)
Flask Framework Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using Twitter for authentication


OAuth was actually born while writing the OpenID API for Twitter. In this recipe, we will integrate Twitter login with our application.

Getting ready

We will continue by building over the Using Google for authentication recipe. It is easy to just implement Twitter auth by leaving out specific parts from Facebook and/or Google authentication.

Now, we have to create an application from the Twitter Application Management page (https://apps.twitter.com/). It will automatically create API key and API secret for us to use. Have a look at the following screenshot:

How to do it…

As always, we will first start with the configuration part in my_app/__init__.py:

from flask_oauth import OAuth

oauth = OAuth()

twitter = oauth.remote_app('twitter',
    base_url='https://api.twitter.com/1.1/',
    request_token_url='https://api.twitter.com/oauth/request_token',
    access_token_url='https://api.twitter.com/oauth/access_token',
    authorize_url='https://api.twitter.com/oauth...