question

Martin Ingham avatar image
Martin Ingham asked ·

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>


username
1 |1000 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

· Write an 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 |1000 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.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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

Work together.
From anywhere.

Team messaging, video meetings
and phone - all in one app.


Get the new RingCentral app