Atozed Forums
Authorization OAUTH2, unknown receiving server port for access token - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Indy (https://www.atozed.com/forums/forum-8.html)
+--- Forum: Indy General Discussion (https://www.atozed.com/forums/forum-9.html)
+--- Thread: Authorization OAUTH2, unknown receiving server port for access token (/thread-1490.html)



Authorization OAUTH2, unknown receiving server port for access token - IndyBeginner - 01-15-2020

Hi! I am working on project to send mails using SMTP server and OAUTH2
autorization mechanism with Indy components. There is a moment, when I 
authorizate and it is necessery to open http server to receive the
access token. Before I open the server, it is necessery to know the
default, free, port. It is possible in some situations, that the
previously chosen port can be unavailable in this moment. I am
wondering, if is it possible to set that the server will choose the
first free port or there is no way to do that and I need to know that
the port I set is free? I am the beginner. Thank You for reply.


RE: Authorization OAUTH2, unknown receiving server port for access token - kudzu - 01-15-2020

Set server port to 0 before starting and it will pick a free available port for you.


RE: Authorization OAUTH2, unknown receiving server port for access token - rlebeau - 01-15-2020

(01-15-2020, 12:38 PM)IndyBeginner Wrote: I am wondering, if is it possible to set that the server will choose the first free port or there is no way to do that and I need to know that the port I set is free?

If the server's Bindings collection is populated before the server is activated, you can set each Binding.Port in the collection as desired.

If the Bindings collection is not populated before activating the server, you can set the server's DefaultPort as desired. When activated, the server will create a default Binding in the collection for you, using the DefaultPort for the Binding.Port.

Setting a given Binding.Port to 0 will let the server ask the OS to pick an available free port for you. Once the server is activated, you can then look at that Binding.Port to see which port it is actually using.


RE: Authorization OAUTH2, unknown receiving server port for access token - IndyBeginner - 01-16-2020

Thank You, Guys, for Your replies. Both help me a lot. @rlebeau answer works perfect and is straight and easy to understand to me Big Grin