Flask Social Authentication - Github & Twitter
Hello! This article presents an open-source project that implements social login for Github and Twitter using Flask and Flask-Dance
library. Β The source code can be downloaded from Github (MIT License) and used in real projects or eLearning activities. Thanks for reading!
- π Flask Social Login - source code
- π Free support via email and Discord (1k+ community)
β¨ How to use the product
Once the source code is downloaded from the public repository, we need to create the OAuth applications on Github and Twitter and use the credentials (ApplicationID and SecretKEY) for project configuration.
π Github Setup - Create an OAuth App
- Sign IN to
Github
- Access
Settings
->Developer Settings
->OAuth Apps
- Edit your OAuth App
- Callback URL:
https://localhost:5000/login/github/authorized
- Generate a
secret key
(used in the configuration)
π Twitter Setup - Create an OAuth App
- Sign IN to
Twitter
- Access
Developer Section
- Create a new APP
- Edit User authentication settings
- Check
OAuth
version: v1 or v2 (recommended) - Callback URL:
https://localhost:5000/login/twitter/authorized
Create a new .env
in the root of the project based on .env.sample
Β and save the credentials provided by Github and Twitter. To compile and start the project, please follow the steps: Β
π Create a new virtual environment & install dependencies
π Set up the environment for Flask
π Start the app using HTTPS
The --cert=adhoc
argument forces Flask to start using HTTPS
protocol, required by OAuth redirects for both platforms.
If all goes well, we should be able to access the app in the browser, authenticate via Github
and Twitter
and also inspect the information provided by each platform when /ping
route is accessed:
Flask Social Login - Twitter Authentication
Github Account info - provided by /ping
route
Thanks for reading! For more resources, feel free to access:
- β¨ Free Starters provided in Flask, Django, and
React
- β¨ Access the documentation or ask for support