Hello,
I have implemented a dash app that uses Google OAuth as authentication mecanism. I used Docker and docker-compose to run the service of the dashboard locally. It worked.
But when I try to deploy the docker image to a website, my-website.com, the git pipeline is run successfully, then I get a 502 Bad Gateway error.
This is a part of my code:
server = Flask(__name__)
server.secret_key = os.urandom(24)
server.config.update({
'GOOGLE_OAUTH_CLIENT_ID': GOOGLE_CLIENT_ID,
'GOOGLE_OAUTH_CLIENT_SECRET': GOOGLE_CLIENT_SECRET,
})
...
app = Dash(__name__,
meta_tags=[
{'name': 'viewport',
'content': 'width=device-width, initial-scale=1.0, maximum-scale=1.2, minimum-scale=0.5,'}],
external_stylesheets=external_stylesheets,
server=server,
url_base_pathname='/',
prevent_initial_callbacks=True
)
authorized_emails = ['user1@gmail.com',
'user2@gmail.com']
additional_scopes = ['openid',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile']
auth = GoogleOAuth(app, authorized_emails=authorized_emails)
@server.route("/")
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 {resp.json()['email']} on Google"
...
context = ('server.crt', 'server.key')
app.run_server(host='0.0.0.0',
port=port,
debug=True,
ssl_context=context
)
I also defined as “Authorized redirect URIs” in Google dev console, the deployment url: https://my-website.com/login/google/authorized
and https://127.0.0.1:8050/login/google/authorized
Do you have any ideas please ?
Thank you