Tutorials>Learn RingCentral OAuth with Node.js and Express

A step by step tutorial to get you started with RingCentral OAuth in Node.js with Express

Start Tutorial

This is a OAuth 2.0 demo using Node.js and Express.

The OAuth 2.0 Authorization Code grant launches a RingCentral login window that handles username password input, including Single Sign-on.

  • Clone the demo repo with git.
  • Install dependencies with NPM

To install NPM, please install Node.js

Configuration

Edit the .env file to configure your client ID, client secret and redirect URL, etc.

$ cp config-sample.env .env
$ vi .env

Please visit Developer Portal to apply client ID and secret. And ensure the redirect URI in your config file has been entered in your app settings. By default, the URL is set to the following for this demo:

http://localhost:8080/oauth2callback

In the node.js entry file, create RingCentral SDK instance with parameters from the configuration file.

Get login URL from RingCentral SDK instance. The authorize_uri in the code is the login URL. It will be passed to the HTML page as template variable by mustache template engine.

When the user click the login button in the HTML page, open a new window with the login URL passed from node.js.

When login finished, plaform will redirect to the callback URL(the configured redirect URL). We handle the callback URL with express route method. In the route method, we can get the auth code from query. With this auth code, we can call the login API of the SDK to log into RingCentral platform.