Four Js Development Tools Forum

Discussions by product => GWS => Topic started by: Jan S. on September 15, 2014, 09:14:56 am



Title: How to get client's IP address?
Post by: Jan S. on September 15, 2014, 09:14:56 am

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


Title: Re: How to get client's IP address?
Post by: Frank G. on September 15, 2014, 10:18:20 am
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


Title: Re: How to get client's IP address?
Post by: Jan S. on September 15, 2014, 10:37:55 am

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


Title: Re: How to get client's IP address?
Post by: Frank G. on September 15, 2014, 03:41:49 pm
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


Title: Re: How to get client's IP address?
Post by: Reuben B. on September 16, 2014, 12:09:27 am
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