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 implement Twitter authentication – simply leave out the Facebook or Google-specific parts from the previous authentication recipes.
First, we have to create an application from the Twitter Application Management page (https://developer.twitter.com/en/portal/dashboard). It will automatically create consumer API keys (API Key and API Key Secret) for us to use, as shown in the following screenshot:
Figure 6.10 – Twitter app configuration
How to do it...
To enable Twitter authentication for your application, follow these steps:
- First, start with the configuration part in
my_app/__init__.py
, as follows:app.config["TWITTER_OAUTH_CLIENT_KEY"] = ...