Flask Social Authentication – Github & Twitter (With Sample)

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 act…


This content originally appeared on DEV Community and was authored by Sm0ke

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 - Github Authentication

✨ 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 - Github Authentication

Flask Social Login - Twitter Authentication

Flask Social Login - Twitter Authentication

Github Account info - provided by the /ping route

Flask Social Login - User Information provided by Github.

Thanks for reading! For more resources, feel free to access:


This content originally appeared on DEV Community and was authored by Sm0ke


Print Share Comment Cite Upload Translate Updates
APA

Sm0ke | Sciencx (2022-01-30T14:06:04+00:00) Flask Social Authentication – Github & Twitter (With Sample). Retrieved from https://www.scien.cx/2022/01/30/flask-social-authentication-github-twitter-with-sample/

MLA
" » Flask Social Authentication – Github & Twitter (With Sample)." Sm0ke | Sciencx - Sunday January 30, 2022, https://www.scien.cx/2022/01/30/flask-social-authentication-github-twitter-with-sample/
HARVARD
Sm0ke | Sciencx Sunday January 30, 2022 » Flask Social Authentication – Github & Twitter (With Sample)., viewed ,<https://www.scien.cx/2022/01/30/flask-social-authentication-github-twitter-with-sample/>
VANCOUVER
Sm0ke | Sciencx - » Flask Social Authentication – Github & Twitter (With Sample). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/30/flask-social-authentication-github-twitter-with-sample/
CHICAGO
" » Flask Social Authentication – Github & Twitter (With Sample)." Sm0ke | Sciencx - Accessed . https://www.scien.cx/2022/01/30/flask-social-authentication-github-twitter-with-sample/
IEEE
" » Flask Social Authentication – Github & Twitter (With Sample)." Sm0ke | Sciencx [Online]. Available: https://www.scien.cx/2022/01/30/flask-social-authentication-github-twitter-with-sample/. [Accessed: ]
rf:citation
» Flask Social Authentication – Github & Twitter (With Sample) | Sm0ke | Sciencx | https://www.scien.cx/2022/01/30/flask-social-authentication-github-twitter-with-sample/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.