Login with Google Sign on Dash app


I have no problem getting a Flask app to use Google Sign In through flask-dance , but I’m unable to make it work with a Dash app. Basically, I expose the Flask server as the user guide says and then use the server to implement the Google Sign In functionality as I do in a Flask app. Yet, when I start the app, I get to the Dash app without getting the Google Sign In page. I copy my (edited) code below. Any help would be more than appreciated:

import dash
import dash_core_components as dcc
import dash_html_components as html

from flask import Flask, redirect, url_for
from flask_dance.contrib.google import make_google_blueprint, google

app = dash.Dash()
server = app.server

blueprint = make_google_blueprint(
    scope=["profile", "email"]

server.register_blueprint(blueprint, url_prefix="/login")

def index():
    if not google.authorized:
        return redirect(url_for("google.login"))
    resp = google.get("/oauth2/v2/userinfo")
    assert resp.ok, resp.text
    return "You are {email} on Google".format(email=resp.json()["email"])

app.layout = html.Div(children=[
    html.H1('Hello Dash')

if __name__ == '__main__':
    server.run(host="", port=80)


Lucas Chapin has a working solution here: https://github.com/lucaschapin/dash-google-auth


I have also implemented the same in my MLM Software Websites


Nice help team. loved it


Hi, I tried using dash-google-auth but I’m getting an error. I did all of the steps from the README.md file and replaced the variables for client ID and client secret with real values like this:

app.server.config["GOOGLE_OAUTH_CLIENT_ID"] = os.environ.get("client-id-here")
        app.server.config["GOOGLE_OAUTH_CLIENT_SECRET"] = os.environ.get("client-secret-here")

However, when I ran python app.py and opened “localhost:5000” in my browser I got the following error:

401. That’s an error.

Error: invalid_client

The OAuth client was not found.

Request Details
scope=profile email
That’s all we know.

I put the following into the “Authorized redirect URIs” field: http://localhost:5000/login/google/authorized

Any idea why I might be getting this error? Thanks.


I recently played around with using flask-dance myself. I wish I had come across Lucas’ repo sooner – I will probably rebase my auth class around his.

If you take a look at what google’s oauth is reporting, the OAuth request isn’t formed properly because client_id=None.

That means that for some reason this line isn’t taking:
app.server.config["GOOGLE_OAUTH_CLIENT_ID"] = os.environ.get("client-id-here")

Maybe try hard-coding the client id and secret and try again? Good luck-

One thing I noted about dash-google-auth: it doesn’t attempt to handle invalid tokens (basically any error types from oauthlib.oauth2.rfc6749.errors). In this case, the client will continue to receive 403 unauthorized until the token is deleted (session clear).