question

yash-patel2380 avatar image
yash-patel2380 asked Anirban answered

Use Access Token to Log In

Hi,


I am trying to use an three-legged authentication in my JavaScript application. I have generated an access_token and now am trying to "Log In" using this token...


In the examples given, something like this has been done:


rcsdk.platform()
    .login({          username: '18001234567', // phone number in full format          extension: '', // leave blank if direct number is used          password: 'yourpassword'      })      .then(function(response) {            // your code here      })      .catch(function(e) {          alert(e.message  || 'Server cannot authorize user');      });



where we can collect username, extension, and password from user to log in. If I have an access token, how should I proceed to log in?

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.

ak avatar image
ak answered
Hi Yash,

Once you get the access code from the RedirectUri, you would need to pass an Array of :

<< Key -Value Pairs >>
code
redirectUri
onto the login function. For reference, you could take a look at our OAuth Demo in Javascript here on line 35
https://github.com/grokify/ringcentral-demos-oauth/blob/master/javascript/public/index.html#L35


1 |3000

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

yash-patel2380 avatar image
yash-patel2380 answered
To clarify, by "access code" you are referring to the "access_token", correct?
1 |3000

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

benjamin-dean avatar image
benjamin-dean answered
No, he means "authorization code". This code is used to obtain an access_token in a 3-Legged (Authorization Code) Auth Flow.

I would try the 3-Legged OAuth JS Demo in the repository link AK shared above ( https://github.com/grokify/ringcentral-demos-oauth/tree/master/javascript).

There is also this older demo code:  http://ringcentral.github.io/tutorial/#login-via-3-legged-oauth
1 |3000

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

yash-patel2380 avatar image
yash-patel2380 answered
I have tried running the demo but it seems that there is an cross-origins issue when hosting locally... any work-arounds?
1 |3000

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

benjamin-dean avatar image
benjamin-dean answered
Did you follow the Usage information that is in the repository directions which show to use http-server to start the application?

This should not run into CORS issues, but it has been a month or so since I've tested the demos.
1 |3000

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

benjamin-dean avatar image
benjamin-dean answered
If you continue experiencing issues with this code, I would submit an Issue with logs and details in the Github issue tracker.  https://github.com/grokify/ringcentral-demos-oauth/issues
1 |3000

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

Anirban avatar image
Anirban answered

First you need to go through using OAuth with Authorization code grant_Type.

Please check here:

https://developers.ringcentral.com/guide/authentication/oauth

https://developers.ringcentral.com/guide/authentication/auth-code-flow

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