# Dash\_google\_auth redirect problem

**URL:** <https://community.plotly.com/t/dash-google-auth-redirect-problem/41656>\
**Category:** Dash Python\
**Created:** [June 27, 2020, 8:51pm UTC](https://community.plotly.com/t/dash-google-auth-redirect-problem/41656 "2020-06-27T20:51:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![florescorreia](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/florescorreia/32/12422_2.png) [@florescorreia](https://community.plotly.com/u/florescorreia)\
**Post date:** [June 27, 2020, 8:51pm UTC](https://community.plotly.com/t/dash-google-auth-redirect-problem/41656/1 "2020-06-27T20:51:37Z")

</div>

Hi,  
Has anyone recently used dash\_google\_auth and/or dash\_okta\_auth with success?  
I was able to make oauth work with okta but not with google.

For okta, the code is the following:

from dash\_okta\_auth import OktaOAuth

server = Flask( **name** )

server.config.update({  
‘OKTA\_OAUTH\_CLIENT\_ID’: ‘XXXXXXXXXX’,  
‘OKTA\_OAUTH\_CLIENT\_SECRET’: ‘XXXXXXXXXXXXX’,  
})  
server.secret\_key = os.environ.get(“FLASK\_SECRET\_KEY”, “anythinggoes”)  
os.environ[‘OAUTHLIB\_INSECURE\_TRANSPORT’] = ‘1’

app = dash.Dash( **name** , server=server, url\_base\_pathname=‘/’)

scopes =   
auth = OktaOAuth(app, base\_url=‘[https://dev-xxxxxx.okta.com](https://dev-xxxxxx.okta.com)’, additional\_scopes=scopes)

#### One possible configuration for the Login redirect URIs at okta is [http://xxxxxxxxxxx/login/okta/authorized](http://xxxxxxxxxxx/login/okta/authorized)

The prescribed code for google auth is the following:

server.config.update({  
‘GOOGLE\_OAUTH\_CLIENT\_ID’: ‘xxxxxxxxxxxxxxxxxxxxxx’,  
‘GOOGLE\_OAUTH\_CLIENT\_SECRET’: ‘xxxxxxxxxxxxxxxxxx’,  
})  
server.secret\_key = os.environ.get(“FLASK\_SECRET\_KEY”, “supersikrit”)  
os.environ[‘OAUTHLIB\_INSECURE\_TRANSPORT’] = ‘1’

app = dash.Dash( **name** , server=server, url\_base\_pathname=‘/’)

emails = [‘xxxxxxxx@gmail.com’']  
scopes =   
auth = GoogleOAuth(app=app, authorized\_emails=emails, additional\_scopes=scopes)

#### One possible configuration for the Login redirect URIs at google is [http://xxxxxxxxxxx/login/google/authorized](http://xxxxxxxxxxx/login/google/authorized)

The problem with google is that after the login I always get redirected back to the login  
[http://xxxxxxxxxxx/login/google/authorized](http://xxxxxxxxxxx/login/google/authorized)  
and the server throws an internal server error (500)

I tried to change the base url by doing

app = dash.Dash( **name** , server=server, url\_base\_pathname=‘/mydashapp/’)

@server.route(‘/mydashapp’)  
def MyDashApp():  
return app.index()

but it still doesn’t work and it gives the same error-- also, I’m not very familiar with Flask, to be honest.

Any help solving this issue? I’ve lost the entire day trying to make this work.

---

<div class="post-metadata">

**Author:** ![ishi](https://avatars.discourse-cdn.com/v4/letter/i/bbce88/32.png) [@ishi](https://community.plotly.com/u/ishi)\
**Post date:** [July 18, 2020, 8:58am UTC](https://community.plotly.com/t/dash-google-auth-redirect-problem/41656/2 "2020-07-18T08:58:11Z")

</div>

I am getting the same exact error. I tried changing the routing as well. Exception comes in because of token validation error:

127.0.0.1 - - [18/Jul/2020 16:52:18] “GET /login/google HTTP/1.1” 302 -  
[2020-07-18 16:52:21,800] ERROR in app: Exception on /login/google/authorized [GET]  
Traceback (most recent call last):  
File “C:\Users\Ishwi\AppData\Local\Programs\Python\Python38\lib\site-packages\flask\app.py”, line 2447, in wsgi\_app  
response = self.full\_dispatch\_request()  
File “C:\Users\Ishwi\AppData\Local\Programs\Python\Python38\lib\site-packages\flask\app.py”, line 1952, in full\_dispatch\_request  
rv = self.handle\_user\_exception(e)  
File “C:\Users\Ishwi\AppData\Local\Programs\Python\Python38\lib\site-packages\flask\app.py”, line 1821, in handle\_user\_exception  
reraise(exc\_type, exc\_value, tb)  
File “C:\Users\Ishwi\AppData\Local\Programs\Python\Python38\lib\site-packages\flask\_compat.py”, line 39, in reraise  
raise value  
File “C:\Users\Ishwi\AppData\Local\Programs\Python\Python38\lib\site-packages\flask\app.py”, line 1950, in full\_dispatch\_request  
rv = self.dispatch\_request()  
File “C:\Users\Ishwi\AppData\Local\Programs\Python\Python38\lib\site-packages\flask\app.py”, line 1936, in dispatch\_request  
return self.view\_functionsrule.endpoint  
File “C:\Users\Ishwi\AppData\Local\Programs\Python\Python38\lib\site-packages\flask\_dance\consumer\oauth2.py”, line 256, in authorized  
token = self.session.fetch\_token(  
File “C:\Users\Ishwi\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\_oauthlib\oauth2\_session.py”, line 360, in fetch\_token  
self.\_client.parse\_request\_body\_response(r.text, scope=self.scope)  
File “C:\Users\Ishwi\AppData\Local\Programs\Python\Python38\lib\site-packages\oauthlib\oauth2\rfc6749\clients\base.py”, line 421, in parse\_request\_body\_response  
self.token = parse\_token\_response(body, scope=scope)  
File “C:\Users\Ishwi\AppData\Local\Programs\Python\Python38\lib\site-packages\oauthlib\oauth2\rfc6749\parameters.py”, line 431, in parse\_token\_response  
validate\_token\_parameters(params)  
File “C:\Users\Ishwi\AppData\Local\Programs\Python\Python38\lib\site-packages\oauthlib\oauth2\rfc6749\parameters.py”, line 461, in validate\_token\_parameters  
raise w

Any help is much appreciated

---

<div class="post-metadata">

**Author:** ![florescorreia](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/florescorreia/32/12422_2.png) [@florescorreia](https://community.plotly.com/u/florescorreia)\
**Post date:** [August 29, 2020, 4:54pm UTC](https://community.plotly.com/t/dash-google-auth-redirect-problem/41656/3 "2020-08-29T16:54:01Z")

</div>

I finally solved it. Google auth is different from Okta auth, since for google you have to provide the email addresses. I was somehow confused. Here is the code (as run on a Ubuntu 20.04 machine):

```auto
from flask import Flask
import dash
from dash_google_auth import GoogleOAuth

server = Flask( __name__ )

server.config.update({
    'GOOGLE_OAUTH_CLIENT_ID': 'xxxxxx',
    'GOOGLE_OAUTH_CLIENT_SECRET': 'xxxxxxx'
})

server.secret_key = os.environ.get('FLASK_SECRET_KEY', 'anything goes')
# dont use for production
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'

external_stylesheets = []
app = dash.Dash( __name__ , server=server, url_base_pathname='/', external_stylesheets=external_stylesheets)
app.config['suppress_callback_exceptions']=True

additional_scopes = ['openid']
authorized_emails = ['xxxxxxx@gmail.com', 'yyyyyy@gmail.com']
auth = GoogleOAuth(app, authorized_emails, additional_scopes)

if __name__ == ' __main__':
   app.run_server(debug=True)

```

---

<div class="post-metadata">

**Author:** ![ishi](https://avatars.discourse-cdn.com/v4/letter/i/bbce88/32.png) [@ishi](https://community.plotly.com/u/ishi)\
**Post date:** [August 30, 2020, 3:48am UTC](https://community.plotly.com/t/dash-google-auth-redirect-problem/41656/4 "2020-08-30T03:48:48Z")

</div>

Thanks for this! We had gotten around this using Google’s IAP since we are on Google cloud.
