The use of third party apps to assist in login is fairly common. It improves a user's experience whenever they want to access content that is protected.
You will need:
Learn how to create a Facebook and a Twitter app in this third party authentication guide. From this guide you will learn how to generate your Facebook and Twitter apps' API Keys and _SecretID. You will need them to run this application locally.
Twitter API working you need "Elevated" Access Level
Screenshot from below Page: https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-leve
Additionally you need to add the below URL to your Callback URI / Redirect URL settings in Twitter developer API
http://127.0.0.1:5000/callback/twitter
If you have only "Essential" Twitter API Access - you will get the below error message in response.
127.0.0.1 - - [07/Jul/2022 03:37:32] "GET /authorize/twitter HTTP/1.1" 302 -
{'errors': [{'message': 'You currently have Essential access which includes access to Twitter API v2 endpoints only. If you need access to this endpoint, you’ll need to apply for Elevated access via the Developer Portal. You can learn more here: https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-leve', 'code': 453}]}
social_id:twitter$None
To test this application, first
$ git clone git@github.com:GitauHarrison/third-party-authentication-using-flask.git
$ mkvirtualenv flask_auth_test # I am using virtualenvwrapper
requirements.txt
:(flask_auth_test)$ pip3 install -r requirements.txt
Run the application:
(flask_auth_test)$ flask run
Before you can run your server, remember to create a .env
file following the guidance seen in the .env-template
. Create a .env
file in the root directory:
(flask_auth_test)$ touch .env
.env
file with all the necessary details. Here is a sample:TWITTER_ID=
TWITTER_SECRET=
FACEBOOK_ID=
FACEBOOK_SECRET=
(flask_auth_test)$ flask run
Once your application is running, you can access your localhost on http://127.0.0.1:5000/. I have not used ngrok
. If you wish to do so, to provision temporary public URLs that will allow access to your application, learn how you can set it up here.
With the application running:
If you do not know how to make a flask application, learn how to do that here.
This application makes use of ngrok
. Learn how to incorporate it in your flask app here.
If you would like to know how to know how to integrate social logins (rather than simply running this application), read more here.