How to get client's IP address?

Started by Jan S., September 15, 2014, 09:14:56 AM

Previous topic - Next topic

Jan S.


Hi,

I am trying to create REST service based on com.WebServiceEngine and com.HTTPServiceRequest classes.
Is there any way how to get client's IP address or hostname?
I didn't find any suitable method in com.HTTPServiceRequest class documentation.

Jan

Frank G.

Hi,

  No, there is no API to get client's IP address or hostname. Actually, it is maybe not the best way to handle authentication or whatever if based on IP address, as it can change over time or be hidden if going through a proxy. But if your client set a specific HTTP header, it will be transmitted and identify the user. And if everything is done overs HTTPS, it is also completely secured.

Why do you exactly need the IP address for ?

Frank

Jan S.


Yes, it's for authentication purpose. I know it's not ideal, but our current authentication mechanism requires it.
I'll be sending IP in HTTP header.

Thanks for reply.

Jan

Frank G.

Hi,

  If your 4GL web service is running behind the GAS, you can get the user-agent IP address the web server (apache or IIS) gave us and that the GAS sets automatically in a HTTP header called : X-FourJs-Environment-Variable-REMOTE_ADDR.

But again, authentication based on IP address is not recommended nor guaranty.

Frank

Reuben B.

A page relevant to what Frank is referring to is hidden in the GAS documentation, see section 3b here https://4js.com/online_documentation/fjs-gas-manual-html/#c_gas_fgl_env_001.html

A good exercise would be to use the various com.HTTPServiceRequest.getRequestHeader* methods and see what is being passed through from the web server

Reuben

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero