question

Cleiton Lenkiu avatar image
Cleiton Lenkiu asked Cleiton Lenkiu answered

JS SDK running on a nodejs app behind proxy

What is the right procedure to run a nodejs application with RC JS SDK behind a proxy?
I am trying to call rcsdk.platform.login() from behind a proxy, but the request never reaches the RC sandbox.

The same request works fine, when running in a box with direct access to the RC sandbox system.


sdk
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tyler Liu avatar image
Tyler Liu answered Tyler Liu edited

Sample code (un-tested):


const platform = rcsdk.platform;
const send = platform.send.bind(platform);
platform.send = (options) => {
    return send({...options, agent: new HttpsProxyAgent('YOUR PROXY SERVER')});
};
platform.login(...);




1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tyler Liu avatar image
Tyler Liu answered Tyler Liu edited

I don't think there are any proxy configurations in JS SDK.

Could you please try


curl https://platform.devtest.ringcentral.com/restapi/v1.0


in your environment?


Can curl reach RingCentral server? If not, could you please configure your proxy to transparently forward HTTP traffic to https://platform.devtest.ringcentral.com ?

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Cleiton Lenkiu avatar image
Cleiton Lenkiu answered

@Tyler Liu,
Yes, RingCentral server can be reach from the command line via curl.

root@umt-virtual-machine:/opt# curl -v --insecure https://platform.devtest.ringcentral.com/restapi/v1.0
* Trying 172.28.12.5...
* TCP_NODELAY set
* Connected to (nil) (172.28.12.5) port 80 (#0)
* Establish HTTP proxy tunnel to platform.devtest.ringcentral.com:443
> CONNECT platform.devtest.ringcentral.com:443 HTTP/1.1
> Host: platform.devtest.ringcentral.com:443
> User-Agent: curl/7.52.1
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 200 Connection established
<
* Proxy replied OK to CONNECT request
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* NPN, negotiated HTTP1.1
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Unknown (67):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: OU=Domain Control Validated; CN=*.devtest.ringcentral.com
* start date: Jul 3 12:19:12 2020 GMT
* expire date: Jul 3 11:31:30 2022 GMT
* issuer: C=US; ST=Arizona; L=Scottsdale; O=GoDaddy.com, Inc.; OU=http://certs.godaddy.com/repository/; CN=Go Daddy Secure Certificate Authority - G2
* SSL certificate verify ok.
> GET /restapi/v1.0 HTTP/1.1
> Host: platform.devtest.ringcentral.com
> User-Agent: curl/7.52.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx
< Date: Tue, 17 Nov 2020 17:56:40 GMT
< Content-Type: application/json;charset=utf-8
< Content-Length: 169
< Connection: keep-alive
< RCRequestId: 3eef543c-28fe-11eb-84ba-005056bb86e2
< RoutingKey: SJC11P01PAS02
< Content-Language: en
< Vary: Accept-Encoding, User-Agent
<
{
"uri" : "https://platform.devtest.ringcentral.com/restapi/v1.0",
"versionString" : "1.0.44",
"releaseDate" : "2020-11-06T00:00:00.000Z",
"uriString" : "v1.0"
* Curl_http_done: called premature == 0
* Connection #0 to host (nil) left intact

But, callling sdk.platform.login() fails to reach the server when running on a nodejs app

FetchError: request to https://platform.devtest.ringcentral.com/restapi/oauth/token failed, reason: connect ETIMEDOUT 192.209.29.78:443

We've set in the server https_proxy and http_proxy environment variable as well we set npm configuration for proxy and https-proxy

It seems to me that the RC sdk doesn't take care of proxy configuration when calling the fetch request.


1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tyler Liu avatar image
Tyler Liu answered Tyler Liu edited

According to https://github.com/node-fetch/node-fetch/issues/79


Solution is


fetch('https://www.google.com',{ agent:new HttpsProxyAgent('http://127.0.0.1:8580')}).then(function(res){
    ...
})


JS SDK supports options: https://github.com/ringcentral/ringcentral-js/blob/986b1ade72b502976a2f892a5ff2bb40a96bc464/sdk/src/platform/Platform.ts#L553-L578


Please have a try and update me. I don't have an env to verify. But I reviewed the relevant code, it should work.

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Cleiton Lenkiu avatar image
Cleiton Lenkiu answered

@Tyler Liu,
Thanks for the answer. The code posted above has solved the proxy issue.


1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys