Robert
Robert

Reputation: 3483

RingCentral JavaScript SDK Handle Redirect URI points to local JavaScript Function

RingCentral JavaScript SDK handle redirect URI point to local JavaScript function

As-per Doc, they give option

RingCentral.SDK.handleLoginRedirect()

but dont know how to use that

var SDK = require('ringcentral');
rcsdk = new SDK({
        server: SDK.server.sandbox,
        appKey: '_app_key',
        appSecret: 'app_password',
        redirectUri: ''
    })
function handleredirectURI(){
//handle redirections
}

We need points out our handleredirectURI function Thanks in advance

Upvotes: 0

Views: 223

Answers (1)

Tyler Liu
Tyler Liu

Reputation: 20366

Per the documentation. The context is 3-legged oAuth. Here is a demo: https://github.com/ringcentral/ringcentral-demos-oauth/tree/master/javascript

However the demo doesn't use the handleredirectURI method. Which means that the method is simply an utility method and it's not required to use it.

For the usage of handleredirectURI, I will come back and update my answer later.

Update

Here is the source code for handleredirectURI: https://github.com/ringcentral/ringcentral-js/blob/669b7d06254d3620c5a5f24c94b401aa862be948/src/SDK.js#L115-L124

You can see that the method parses win.location to get some useful data and postMessage back to its opener.

Unit tests for handleredirectURI: https://github.com/ringcentral/ringcentral-js/blob/669b7d06254d3620c5a5f24c94b401aa862be948/src/SDK-spec.js#L27-L63

Update 2

I read handleredirectURI' source code, unit tests, sample code again and I think its usage is just like what is written in its documentation:

Popup Setup

This setup is good when your app is rendered as a widget on a third-party sites.

If you would like to simply open RingCentral login pages in a popup, you may use the following short-hand in your app's login page:

var platform = rcsdk.platform();
var loginUrl = platform.loginUrl({implicit: true}); // implicit parameter is optional, default false
platform
    .loginWindow({url: loginUrl}) // this method also allows to supply more options to control window position
    .then(function (loginOptions){
        return platform.login(loginOptions);
    })
    .then(...)
    .catch(...);

In this case your landing page (the one to which Redirect URI points) need to call the following code:

RingCentral.SDK.handleLoginRedirect();

Explained:

  • Run the first code snippet to open the login popup.
  • In the redirected to page, run the second code snippet (that one line of code) to get everything else done.
  • After that the authorization part is done and you can invoke other APIs.

Let me know if you have more questions.

Upvotes: 1

Related Questions