Flask Social Login - Github & Twitter | AppSeed
OTHER License
Open-source Flask Sample built on top of flask-dance
library. The project implements the social login for Github and Twitter - Originally coded by TestDriven.IO.
Features:
Up-to-date dependencies
OPENID
Social login over Flask Dance
SQLite
Persistence, SQLAlchemy
ORMStep #1 - Clone sources (this repo)
$ # Clone the sources
$ git clone https://github.com/app-generator/sample-flask-auth-social.git
$ cd sample-flask-auth-social
Step #2 - Create a virtual environment
$ # Virtualenv modules installation (Unix based systems)
$ virtualenv env
$ source env/bin/activate
$
$ # Virtualenv modules installation (Windows based systems)
$ # virtualenv env
$ # .\env\Scripts\activate
Step #3 - Install dependencies
$ pip3 install -r requirements.txt
Step #4 - Set Up Environment
$ # Set the FLASK_APP environment variable
$ (Unix/Mac) export FLASK_APP=run.py
$ (Windows) set FLASK_APP=run.py
$ (Powershell) $env:FLASK_APP = ".\run.py"
Step #5 - (optional) Enable DEBUG Environment (local development)
$ # Set up the DEBUG environment
$ (Unix/Mac) export FLASK_ENV=development
$ (Windows) set FLASK_ENV=development
$ (Powershell) $env:FLASK_ENV = "development"
Github Setup - Create an OAuth App
Github
Settings
-> Developer Settings
-> OAuth Apps
App Name
App Description
HomePage
: https://localhost:5000
Authorization callback URL
: https://localhost:5000/login/github/authorized
secret key
Twitter Setup - Create an OAuth App
Twitter
Developer Section
-> https://developer.twitter.com/en/portal/projects-and-apps
OAuth 1.0a
HomePage
: https://www.localhost:5000
Authorization callback URL
: https://127.0.0.1:5000/login/twitter/authorized
Update Environment - Rename
.env.sample
to.env
and edit the file
GITHUB_ID
- value provided by Github Setup
GITHUB_SECRET
- value provided by Github Setup
TWITTER_ID
- value provided by Twitter Setup
TWITTER_SECRET
- value provided by Twitter Setup
Start the project Using HTTPS
$ flask run --cert=adhoc
$
$ # Access the app: HTTPS://127.0.0.1:5000/
Important: The --cert=adhoc
will force the https protocol
Once the user is authenticated, all available information can be accessed via /ping
route:
Github sample (truncated):
https://localhost:5000/ping
{
"avatar_url": "https://avatars.githubusercontent.com/u/51070104?v=4",
"bio": "App Generator and Boilerplate Code.",
"blog": "https://appseed.us/app-generator",
"company": "AppSeed",
"created_at": "2019-05-27T04:55:15Z",
"followers": 777,
"public_repos": 495,
"url": "https://api.github.com/users/app-generator"
}
Successfull
Github
Login
Successfull
Github
account information
Flask Social Login (Twitter & Github) - Free sample provided by AppSeed App Generator.