google-auth-library-python-oauthlib
google-auth-library-python-oauthlib copied to clipboard
make redirect host configurable
I am using docker for windows which runs the docker daemon inside a Hyper-V VM.
This library is used inside a docker container and for authentication purposes the corresponding port is exposed to my machine. This way I can access the launched WSGI server on localhost on my machine, however the server inside the docker container does only listen on the ip behind localhost resolved within the container -> You do not receive an answer for localhost on your machine, only within the container (e.g. with curl)
This could easily be mitigated by passing an empty String as host
parameter to the Flow.run_local_server
function, but this will raise an error because the redirect url is equal to the chosen host string -> empty URL is not possible
As a solution the function could be extended by an optional parameter redirect_host
that defaults to the value of host
and is inserted into the redirect_host
variable.
Hi @hacker-h,
I'm having a bit of trouble understanding the request. Would you mind providing a short example?
As run_local_server
is currently written, the host
and port
values are used to construct redirect_uri
.
You can basically just launch an ubuntu docker container on docker for windows exposing port 8080:
docker run --name testContainer -it -p 8080:8080 ubuntu
follow the quickstart steps from https://developers.google.com/drive/api/v3/quickstart/python
apt update && apt install curl python3-pip -y && pip3 install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
paste the credentials.json along with the quickstart script into the container (e.g. with cat > FILE
or echo '...' > FILE
)
https://github.com/gsuitedevs/python-samples/blob/master/drive/quickstart/quickstart.py
Make sure to adapt the port specified in the quickstart script to 8080
.
run the script:
python3 quickstart.py
open the printed URL in your browser and confirm the access
At the end you will be redirected to a page localhost:8080?state=[...]
which tells you that the server reset the connection while trying to load the page.
Copy the URL and open a terminal to enter your container:
docker exec -it testContainer bash
Use curl to send a GET request against the copied URL from within the container:
curl http://localhost:8080/?state=[...]
You will get an output:
The authentication flow has completed[...]
I hope this helps to reproduce and understand the problem.
I ran into the same problem with docker and would find such a feature very useful.