Skip to content


For Flask applications, we recommend Requests-OAuthlib, a library to integrate OAuth providers. This library is also used by social-app-django to add social login buttons to Django apps

The code example is on


First please install Requests-OAuthlib:

pip3 install requests_oauthlib

Then please store your SimpleLogin AppID and AppSecret somewhere, preferably in env variable as recommended in the The Twelve Factors.

export CLIENT_ID={your_app_id}
export CLIENT_SECRET={your_app_secret}

Bootstrap the app

import requests_oauthlib, os, flask

# Get SimpleLogin AppID, AppSecret from env vars
CLIENT_ID = os.environ.get("CLIENT_ID")

app = flask.Flask("my-app")
app.secret_key = "my-super-secret"  # for flask.session

# This allows us to test the app using HTTP.
# Please make sure to disable it in production

Login endpoint

When user clicks on Sign in with SimpleLogin, user gets redirected to the SimpleLogin authorization page. This is done using the /login endpoint. The state is necessary to defend against CSRF attack.

import requests_oauthlib, os, flask

def login():
    sl = requests_oauthlib.OAuth2Session(
        # this supposes you are running your app on the default port 5000

    redirect_url, state = sl.authorization_url(

    # State is used to prevent CSRF, keep this for later.
    flask.session["oauth_state"] = state

    return flask.redirect(redirect_url)

Callback endpoint

When user approves sharing data with your app, they get redirected back to the redirect_uri in the previous step. This route is handled by an endpoint that receives the code and exchanges for access token. The access token is then used to exchange for user info:

def callback():
    sl = requests_oauthlib.OAuth2Session(
        CLIENT_ID, state=flask.session.get("oauth_state")
    # Get the "access token"

    user_info = sl.get("").json()

    # This is where you log user in,
    # for ex via flask-login extension: login_user(user)
    return f"""
    Welcome {user_info["name"]} <br>
    Your email is {user_info["email"]} <br>
    And your avatar: <img src="{user_info['avatar_url']}">

Run the App and enjoy!

Let's run the app

flask run

Now you should be able to SLWSL at http://localhost:5000/login