Redirect to OAuth URL with headers Redirect to OAuth URL with headers flask flask

Redirect to OAuth URL with headers


You will need to build your own response object to add headers. You can check out the docs here: http://docs.python-requests.org/en/master/api/#requests.Response

A simple example for your use case would be something like:

response = Response(headers={'Authorization': 'whatever'},                    is_redirect=True,                    url="https://your-redirected-url.com")return response

Edit: Further info

Also, I would check out https://github.com/lepture/flask-oauthlib if you are interested in using a library. It has support for oAuth1 and oAuth2 and it is relatively easy to setup with a standard Flask app.

Edit: Another way of doing it

This morning I remembered a simpler way to do this. You can call the redirect function and it will return a flask Response object. Then you are able to set the headers on that newly created object.

response = redirect('https://url')response.headers = {'authorization': 'whatever'}  return response