You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.
I'm implementing a native desktop app that has the user sign in with OAuth. In order for this to be possible, the app has to launch a local webserver on a random available port and use 127.0.0.1:port as the return address so that the app can receive the authentication information (or cancellation). Then when the user is directed to the local webserver, they should see a message telling them to return to the app, and the webserver should shutdown.
I am running into problems with this every step of the way. Firstly, the port number - using port 0 lets the operating system choose a random available port, and then the port can be queried with acceptor->local_endpoint().port(). However, since the acceptor is only initialized in start() and start() is called in a separate thread, there's no way to reliably know when it can be accessed. My current workaround is to just wait 100 milliseconds after starting the server and just hope that that is enough time, which is an obviously horrible hack.
Secondly, there's no way to know when the response has finished being sent. Since the user handler functions must return before the response can be sent, my app has no way of knowing when it is safe to shut down the server. I have tried counting the number of open connections but there is for some reason always one open connection at all times despite setting close_connection_after_response, I don't know what this is from. As a workaround I could include an image in the response body and shut down the server when that image is requested, but that's another obviously horrible hack on a number of levels.
Do you have any suggestions for how to deal with these problems?
The text was updated successfully, but these errors were encountered:
I'm implementing a native desktop app that has the user sign in with OAuth. In order for this to be possible, the app has to launch a local webserver on a random available port and use
127.0.0.1:port
as the return address so that the app can receive the authentication information (or cancellation). Then when the user is directed to the local webserver, they should see a message telling them to return to the app, and the webserver should shutdown.I am running into problems with this every step of the way. Firstly, the port number - using port 0 lets the operating system choose a random available port, and then the port can be queried with
acceptor->local_endpoint().port()
. However, since theacceptor
is only initialized instart()
andstart()
is called in a separate thread, there's no way to reliably know when it can be accessed. My current workaround is to just wait 100 milliseconds after starting the server and just hope that that is enough time, which is an obviously horrible hack.Secondly, there's no way to know when the response has finished being sent. Since the user handler functions must return before the response can be sent, my app has no way of knowing when it is safe to shut down the server. I have tried counting the number of openconnections
but there is for some reason always one open connection at all times despite settingclose_connection_after_response
, I don't know what this is from. As a workaround I could include an image in the response body and shut down the server when that image is requested, but that's another obviously horrible hack on a number of levels.Do you have any suggestions for how to deal with these problems?
The text was updated successfully, but these errors were encountered: