Code Monkey home page Code Monkey logo

exp20-token-exchange's Introduction

Token Exchange Service (NodeJS)

This service provides a reference implementation for a Token Exchange service that can be used with a Custom Tool or Plugin inside one of Ellie Mae's web-based applications (LO Connect, TPO Connect). Token Exchange allows a customization to obtain an API Access Token that can be used to invoke the Ellie Mae REST APIs.

Installation

To install the Token Exchange Service, download the source code to a local folder and run:

npm install

You must have NodeJS installed and the npm package manager executable in your path.

Configuration

Before you can run the tool, you must configure it by creating a file named oauth.js in the root folder of the application. This file should contain the following contents:

module.exports = {
   host: "<api_hostname>",   // e.g. api.elliemae.com
   clientId: "<oauth_cid>",
   secret: "<oauth_secret>"
}

The OAuth Client ID and Secret must correspond to a valid Encompass instance for the environment referenced by the api_hostname.

Running the Service

Once the configuration file is created, you can run the service by executing the following:

node tokensvc.js

The service is configured to run on port 8081, and you can test the service by querying the /health endpoint of the service:

GET http://localhost:8081/health

The service should respond with the following JSON object:

{ "status": "OK" }

Invoking the Service

To invoke the service in your custom code, you can call perform a token exchange as follows:

    const http = await elli.script.getObject('http');
    const auth = await elli.script.getObject('auth');

    // Generate an auth code from the host application
    let authCode = await auth.createAuthCode();

    // Invoke the token excahnge API
    let tokenResp = await http.post('http://localhost:8081/api/token', 
        { "Content-Type": "application/json" }, 
        { authCode: authCode }
    );

    if (tokenResp.status != 200) {
        throw "Unable to perform token exchange";
    }

    // Extract the access token from the response
    accessToken = tokenResp.body.access_token;

You can now use this accessToken to invoke Encompass APIs.

exp20-token-exchange's People

Contributors

em-kkolda avatar

Watchers

James Cloos avatar Anthony avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.