question

Bob Lozinak avatar image
Bob Lozinak asked Phong Vu commented

Javascript SDK state for oAuth 2

I would like to be able to send the state when I call LoginWindow. I can not find any documentation on the SDK. How do I pass in a state for the OAuth?

    RC.state = utils.uuid();
    var rcsdk = new RingCentral.SDK({
        server: RingCentral.SDK.server.sandbox,
        clientId: RC.RingCentralClientID ,
        clientSecret: RC.RingCentralClientSecret,
        redirectUri: RC.RingCentralRedirectURL, // optional, but is required for Implicit Grant and Authorization Code OAuth Flows (see below)
        state: RC.state
    }); 
    console.log(RC.state);
    var loginUrl = rcsdk.loginUrl({implicit: false}); // implicit parameter is optional, default false
    console.log(loginUrl);

This does not work, st the URL does not have the state in it, or is it passed back to the Redirect URL.

authenticationoauth2developers
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.

Phong Vu avatar image
Phong Vu answered

You have to create an AuthorizeRequest object and call the rc.authorizeUri() method.

https://github.com/ringcentral/ringcentral-java/blob/master/src/main/java/com/ringcentral/RestClient.java#L322

https://github.com/ringcentral/ringcentral-java/blob/master/src/main/java/com/ringcentral/definitions/AuthorizeRequest.java


See the sample code on this quick start

https://developers.ringcentral.com/guide/authentication/quick-start#java

// Replace this
response.getWriter().println("<h2>RingCentral Authorization Code Flow Authentication</h2><a href=\"" + rc.authorizeUri(REDIRECT_URI) + "\">Login RingCentral Account</a>");

// With this
response.getWriter().println("<h2>RingCentral Authorization Code Flow Authentication</h2><a href=\"" + rc.authorizeUri("Your-AuthorizeRequest-Object") + "\">Login RingCentral Account</a>");            
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.

Bob Lozinak avatar image
Bob Lozinak answered Phong Vu commented

Phong, Thank you for the quick response. But these examples are in Java and I am not familiar with Java. Do you have the same in Javascript?

1 comment
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.

Oops, how come I saw it Java??? Too tired.

https://developers.ringcentral.com/guide/authentication/quick-start#javascript

app.get('/', async function(req, res) {
  var platform = rcsdk.platform()
  if (req.session.tokens != undefined) {
    platform.auth().setData(req.session.tokens)
    if (await platform.loggedIn()) {
      return res.render('test')
    }
  } else {
    res.render('index', {
      authorize_uri: platform.loginUrl({
        redirectUri: RINGCENTRAL_REDIRECT_URL,
        state: "state string",
        ...
      })
    });
  }
})


0 Likes 0 ·

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