The Getting Started guide will get you pretty far in node land, but at some point, you’ll probably want more users than just yourself.

Before you can login users with OAuth, you’ll need to register a new application on the Cisco Webex for Developers portal. You’ll need to set some of the values from that page as environment variables:

  • WEBEX_CLIENT_ID
  • WEBEX_CLIENT_SECRET
  • WEBEX_REDIRECT_URI
  • WEBEX_SCOPE

Init

Use Webex.init() to create new Webex instance and initialize it using the URL you got from the portal and your client secret.

var Webex = require('webex');
const webex = Webex.init({
  config: {
    credentials: {
      authorizationString: <your auth URL>,
      client_secret: <your client secret>
    }
  }
});

Use the authorization URL you got from the developer portal to authenticate your users and get back an auth code. Then, pass that auth code to webex

webex.authorization.requestAuthorizationCodeGrant({code: <code>})
  .then(function() {
    // webex is authorized
  });

By default, webex stores credentials and some other registration data in memory, but we provide a generic interface - inspired by leveldb - for hooking in your own cache layer. See Storage Layer for more details.

Express Example

The following is an approximation of how an expressjs app might do authentication. It assumes you’re using a session middleware of some kind that puts a user identifier on each request. The function storageAdapterForYourBackend would produce a storage adapter bound to the user specified in the request object.

OAuth Route Handlers

var Webex = require('webex');
const assert = require(`assert`);

app.use(function(req, res, next) {
  req.webex = Webex.init({
    config: {
      credentials: {
        authorizationString: <your auth URL>,
        client_secret: <your client secret>
      },
      storage: {
        boundedAdapter: storageAdapterForYourBackend(req.session.id)
      }
    }
  });

  req.webex.once(`ready`, next);
});

app.get(`/login`, (req, res) => {
  // buildLoginUrl() defaults to the implicit grant flow, so explicitly pass `confidential`
  res.redirect(req.webex.credentials.buildLoginUrl({clientType: 'confidential'})).end();
});

app.get(`/oauth/redirect`, (req, res) => {
  assert(req.params.code);
  req.webex.authorization.requestAuthorizationCodeGrant(req.params)
    .then(() => {
      res.redirect(`/`).end();
    });
});