Hello Coders!
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 - Set 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
- Set the
OAuth
version: v1 or v2 (recommended) - Set 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, follow the steps:
👉 Install modules
$ virtualenv env
$ source env/bin/activate
$ pip3 install -r requirements.txt
👉 Set up the environment for Flask
$ export FLASK_APP=run.py
$ export FLASK_ENV=development
👉 Start the app using HTTPS
$ flask run --cert=adhoc
The --cert=adhoc
argument forces Flask to start using HTTPS protocol, required by OAuth redirects for bot 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 the
/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
Top comments (7)
Thank you! how hard it is to extend the code for Google?
The codebase requires only three things for each provider:
Flask-Dance
(copy/paste work)🚀🚀
Sounds easy :)
Thanks again
Super useful, ty!
🚀🚀
Thank you very much for sharing
🚀🚀