Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 30, 2022 02:06 pm GMT

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 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:


Original Link: https://dev.to/sm0ke/flask-social-authentication-github-twitter-with-sample-gnc

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To