News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Javascript SDK state for oAuth 2
Tags: sdk
Feb 16, 2021 at 12:34pm   •   2 replies  •  0 likes
Bob Lozinak

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.

2 Answers
answered on Feb 17, 2021 at 6:01am  

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?


 0
on Feb 17, 2021 at 8:02am   •  0 likes

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",
        ...
      })
    });
  }
})


answered on Feb 16, 2021 at 3:00pm  

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>");            

 0



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us