question

Martin Ingham avatar image
Martin Ingham asked Phong Vu answered

CORS error when trying to login

I am only just starting using RingCentral and I am getting this error when attempting to login :

Access to fetch at 'https://platform.devtest.ringcentral.com//restapi/oauth/token' from origin 'http://localhost:51841' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I am using example code from github.com/ringcentral/ringcentral-js-client

<script type="text/javascript" src="~/Scripts/RingCentral/ringcentral.min.js"></script>

<script type="text/javascript">

var sdk = new RingCentral.SDK({

server: 'https://platform.devtest.ringcentral.com/',

clientId: '<clientid>',

clientSecret: '<clientsecret>'

});

sdk.platform().login({

"username": "<userid>",

"extension": "101",

"password": "<pwd>"

}).then(() => {

console.log("login success");

}).then((accountinfo) => {

console.log("current account info", accountinfo);

}).then(() => {

console.logout("logout success");

}).catch(e => {

console.error("Error", e);

});

</script>


getting started
1 |1500 characters needed characters left characters exceeded

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

1 Answer

Phong Vu avatar image
Phong Vu answered

This is a common issue when it comes to security policy of your local environment. You can enable or disable the CORS to solve the problem. Maybe this article would help you understand better before you change that setting. Or simply browse the Internet for more information about CORS.

Back to the RingCentral JS SDK. The quick start section is just a quick reference and it should not be used when using the SDK on the client side. It is because you will expose the user login credentials on your page source code. That method is suitable for using the SDK in the server side only.

Please refer to this JS SDK for more details.

1 |1500 characters needed characters left characters exceeded

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