Python2.7 / Flask / oidc / Blog Error


I think I have followed the instructions correctly from the Flask+oid blog post but I am getting the error after logging in to my Okta page. I would appreciate a second set of eyes on this if possible:

My error is:

[2019-01-22 21:22:57,223] ERROR in app: Exception on /oidc/callback [GET]  
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/", line 2292, in wsgi_app
response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/flask/", line 1813, in full_dispatch_request
rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python2.7/dist-packages/flask_oidc/", line 657, in _oidc_callback
plainreturn, data = self._process_callback('destination')
  File "/usr/local/lib/python2.7/dist-packages/flask_oidc/", line 689, in _process_callback
credentials = flow.step2_exchange(code)
  File "/usr/local/lib/python2.7/dist-packages/oauth2client/", line 133, in     positional_wrapper
return wrapped(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/oauth2client/", line 2089, in step2_exchange
raise FlowExchangeError(error_msg)   
FlowExchangeError: Invalid response: 302. - - [22/Jan/2019 21:22:57] "GET /oidc/callback?code=lW46rx2dZXspEFmSYQ_W&state=eyJjc3JmX3Rva2VuIjogImptWk5vQ0ZpVmRyRklrOW5UT0dvUldFSVl1M1VVR2diIiwgImRlc3RpbmF0aW9uIjogImV5SmhiR2NpT2lKSVV6VXhNaUo5LkltaDBkSEE2THk5c2IyTmhiR2h2YzNRNk5UQXdNQzlzYjJkcGJpSS45cEg5MkVsdTlISXhxQ2N0bzdsRlpLa0VHck9rM2hIelpfVDE2XzZ2NF9JLWlzMjVrM2dDdS1SMGdRT1QtTXdDc0M5Zi1kRDF6QVNvQ1puWnptbjY4USJ9 HTTP/1.1" 500 -

I have tried adding /login to the redirect URIs but no success.

Used code bits from the samples-okta github and resolved the problem.

1 Like

Hello Chudel, can you tell me which code snippets you used ? I am having the same error.

Hi @brijeshpatel

The samples for Flask can be found here.