Bind Live PingOne Data in Wijmo FlexGrid with CData API Server

Mohsin Turki
Mohsin Turki
Technical Marketing Engineer
With CData API Server, easily create OData endpoints for live PingOne data and seamlessly connect and bind them to Wijmo's FlexGrid for real-time, interactive data access without manual data movement.

Wijmo FlexGrid is a lightweight, high-performance JavaScript datagrid for creating responsive, interactive data applications.

With the CData API Server and the PingOne Connector (or any of the hundreds of available connectors), you can quickly create APIs that expose live data from multiple sources, using industry standards like OData and Swagger for seamless integration with client-side and server-side controls in Wijmo's FlexGrid.

In this article, we'll use the Wijmo FlexGrid JavaScript components to build a simple HTML page that lets you select tables and columns from PingOne and display the data.

Let's get started!

Prerequisites

  1. CData API Server: Download a free trial here.
  2. Wijmo FlexGrid: No downloads are required for this example, but you can sign up for a free trial here.
  3. An active PingOne account with access to your data.

Overview

Here's a quick overview of the steps we'll follow:

  1. Install the CData API Server, configure a connection to PingOne, and expose OData endpoints.
  2. Bind Wijmo Grid to the live OData feed for real-time data access and interaction.

Step 1: Install the CData API Server and Add a Connection to PingOne

1.1 Install the API Server

If you haven't already, download an installer for your machine from the CData API Server page. Follow the installation instructions to complete the setup.

Once installed, you can start the server in the following ways:

  • Windows: CData API Server runs as a service by default. Make sure the service is running, then open http://hostname:port (e.g., http://localhost:8080/) in your browser to access the API Server admin console.
  • Linux/Mac: You can run the server manually or as a service. To start it manually, navigate to the installation directory and run java -jar apiserver.jar.
  • Alternatively, run service.sh with root privileges to set up API Server as a Linux system service.

1.2 Enable CORS

When your Wijmo Grid application and the CData API Server are hosted on different domains, CORS (Cross-Origin Resource Sharing) must be enabled. To enable CORS in the API Server:

  1. Go to Settings and click the icon to edit CORS settings.
  2. Enable Cross-Origin Resource Sharing (CORS).
  3. Enable Allow all domains without '*' to accept any origin.
  4. In Access-Control-Allow-Origin, enter your PingOne origin domain, or use * to allow all domains (suitable for public APIs).
  5. Enable Access-Control-Allow-Credentials to allow cookies and auth headers.
  6. In Access-Control-Allow-Methods, enter GET, PUT, POST, OPTIONS.
  7. In Access-Control-Allow-Headers, enter Authorization, Content-Type.
  8. Set Access-Control-Max-Age (default: 3600 seconds).
  9. Click Save.

1.3 Add a PingOne Connection in the API Server

  1. Go to Settings and click Add Connection in the top-right.
  2. Select PingOne. If it's not visible, toggle off Only Installed to view all connectors.
  3. Click Install Connector to auto-install. For a manual setup, choose Manual Install and upload the obtained ZIP file.
  4. Once installed, click PingOne to configure connection settings.
  5. To connect to PingOne, configure these properties:

    • Region: The region where the data for your PingOne organization is being hosted.
    • AuthScheme: The type of authentication to use when connecting to PingOne.
    • Either WorkerAppEnvironmentId (required when using the default PingOne domain) or AuthorizationServerURL, configured as described below.

    Configuring WorkerAppEnvironmentId

    WorkerAppEnvironmentId is the ID of the PingOne environment in which your Worker application resides. This parameter is used only when the environment is using the default PingOne domain (auth.pingone). It is configured after you have created the custom OAuth application you will use to authenticate to PingOne, as described in Creating a Custom OAuth Application in the Help documentation.

    First, find the value for this property:

    1. From the home page of your PingOne organization, move to the navigation sidebar and click Environments.
    2. Find the environment in which you have created your custom OAuth/Worker application (usually Administrators), and click Manage Environment. The environment's home page displays.
    3. In the environment's home page navigation sidebar, click Applications.
    4. Find your OAuth or Worker application details in the list.
    5. Copy the value in the Environment ID field. It should look similar to:
      WorkerAppEnvironmentId='11e96fc7-aa4d-4a60-8196-9acf91424eca'

    Now set WorkerAppEnvironmentId to the value of the Environment ID field.

    Configuring AuthorizationServerURL

    AuthorizationServerURL is the base URL of the PingOne authorization server for the environment where your application is located. This property is only used when you have set up a custom domain for the environment, as described in the PingOne platform API documentation. See Custom Domains.

    Authenticating to PingOne with OAuth

    PingOne supports both OAuth and OAuthClient authentication. In addition to performing the configuration steps described above, there are two more steps to complete to support OAuth or OAuthCliet authentication:

    • Create and configure a custom OAuth application, as described in Creating a Custom OAuth Application in the Help documentation.
    • To ensure that the driver can access the entities in Data Model, confirm that you have configured the correct roles for the admin user/worker application you will be using, as described in Administrator Roles in the Help documentation.
    • Set the appropriate properties for the authscheme and authflow of your choice, as described in the following subsections.

    OAuth (Authorization Code grant)

    Set AuthScheme to OAuth.

    Desktop Applications

    Get and Refresh the OAuth Access Token

    After setting the following, you are ready to connect:

    • InitiateOAuth: GETANDREFRESH. To avoid the need to repeat the OAuth exchange and manually setting the OAuthAccessToken each time you connect, use InitiateOAuth.
    • OAuthClientId: The Client ID you obtained when you created your custom OAuth application.
    • OAuthClientSecret: The Client Secret you obtained when you created your custom OAuth application.
    • CallbackURL: The redirect URI you defined when you registered your custom OAuth application. For example: https://localhost:3333

    When you connect, the driver opens PingOne's OAuth endpoint in your default browser. Log in and grant permissions to the application. The driver then completes the OAuth process:

    1. The driver obtains an access token from PingOne and uses it to request data.
    2. The OAuth values are saved in the location specified in OAuthSettingsLocation, to be persisted across connections.

    The driver refreshes the access token automatically when it expires.

    For other OAuth methods, including Web Applications, Headless Machines, or Client Credentials Grant, refer to the Help documentation.

  6. Click Save & Test to validate and complete the connection setup.

1.4 Add and Configure Users

To allow secure access to the created OData endpoints, create and configure Users in the API Server.

  1. Go to Users from the navigation pane, then click Add User.
  2. Set a Username and Password.
  3. Select a Role: Select Admin for full access and Query for limited access.
  4. Define user Privileges (GET, POST, PUT, DELETE, etc.).
  5. Click Add User to save.

Once a user is added, an Authtoken is automatically generated. This token can be used in API requests as a secure authentication method instead of a password.

You can also refresh the Authtoken, disable it, or set expiration rules (e.g., number of days until expiry) by enabling the Token Expiration option in the user settings.


1.5 Add Tables for the Endpoint

To make data from PingOne accessible in Wijmo Grid via OData, you need to expose your desired tables through the API Server. Here's how:

  1. In the API Server, go to API and click Add Table.
  2. Select the PingOne connection and click Next.
  3. Choose the tables you want to expose and click Confirm.

1.6 Access the Endpoints in Wijmo FlexGrid

Now that your API is configured, Wijmo FlexGrid can connect to the OData endpoints to display live data. Below are the URL formats for OData endpoints that you can use:

Endpoint   URL
Entity List http://address:port/api.rsc/
Table Metadata (e.g., albums) http://address:port/api.rsc/albums/$metadata?@json
Table Data (e.g., albums) http://address:port/api.rsc/albums

These OData endpoints are now ready to be directly consumed in Wijmo FlexGrid using the URL. Since Wijmo FlexGrid supports OData, you can easily bind live data from PingOne and create dynamic, interactive grids.

The CData API Server supports full OData filtering capabilities. For custom queries and filtered visualizations, you can append standard OData query parameters like $select, $filter, $orderby, $top, and $skip to your requests.


Step 2: Build the Simple Wijmo Grid

You've got the CData API Server up and running now with consumable OData endpoints from your PingOne data. Now let's build a simple Wijmo FlexGrid that lets you select tables and columns and view your data.

  1. Get the CData API Endpoint URL by logging into your CData API Server. Go to API from the left navigation, then click View Endpoints at the top-right.
  2. Copy the URL (e.g., http://localhost:8080/api.rsc).
  3. Create a new HTML file and give it a name (e.g., Wijmo-Grid.html).
  4. Paste the following code into your HTML file.
  5. Update the following placeholder values at the start of the script section:
    • yourUsername: Replace with your CData API Server username.
    • yourPassword: Replace with your CData API Server password.
    • Your_CData_API_Server_URL: Replace with the full API endpoint URL you copied earlier.
    <!DOCTYPE html>
    <html lang="en">
    <head>
    
      <meta charset="UTF-8">
      <title>Wijmo Grid with CData API Server</title>
    
      <!-- Wijmo styles -->
      <link href="https://cdn.mescius.com/wijmo/5.latest/styles/wijmo.min.css" rel="stylesheet" />
    
      <!-- Wijmo core and controls -->
      <script src="https://cdn.mescius.com/wijmo/5.latest/controls/wijmo.min.js"></script>
      <script src="https://cdn.mescius.com/wijmo/5.latest/controls/wijmo.grid.min.js"></script>
      <script src="https://cdn.mescius.com/wijmo/5.latest/controls/wijmo.input.min.js"></script>
      <script src="https://cdn.mescius.com/wijmo/5.latest/controls/wijmo.odata.min.js"></script>
    
    <style>
        body {
          font-family: Arial, sans-serif;
          margin: 20px;
        }
        h1 {
          color: #00A0FF;
          text-align: center;
        }
        #selectors {
          display: flex;
          flex-wrap: wrap;
          gap: 15px;
          justify-content: center;
          align-items: flex-start;
          margin-bottom: 20px;
        }
        .select-group {
          display: flex;
          flex-direction: column;
          min-width: 200px;
        }
        label {
          font-weight: bold;
          margin-bottom: 5px;
          color: #00A0FF;
        }
        select, button {
          padding: 6px;
          font-size: 14px;
          border: 1px solid #00A0FF;
          border-radius: 4px;
        }
        button {
          background: #00A0FF;
          color: white;
          cursor: pointer;
          height: 40px;
          margin-top: 24px;
        }
        #columnsContainer {
          display: flex;
          flex-direction: column;
          gap: 5px;
          max-height: 150px;
          overflow-y: auto;
          border: 1px solid #00A0FF;
          padding: 8px;
          border-radius: 4px;
        }
        #theGrid {
          margin-top: 20px;
          border: 2px solid #00A0FF;
          height: 500px;
        }
        .wj-header {
          background: #00A0FF !important;
          color: white !important;
          font-weight: bold;
        }
      </style>
    
    </head>
    <body>
    
    <h1>Simple Wijmo Grid with CData API Server</h1>
    
      <div id="selectors">
        <div class="select-group">
          <label for="tableSelect">Select Table</label>
          <select id="tableSelect"></select>
        </div>
    
        <div class="select-group">
          <label>Select Columns</label>
          <div id="columnsContainer"></div>
        </div>
    
        <div>
          <button onclick="loadGrid()">Load Grid</button>
        </div>
      </div>
    
      <div id="theGrid"></div>
    
    <script>
        const username = 'yourUsername';
        const password = 'yourPassword';
        const authHeader = 'Basic ' + btoa(username + ':' + password);
        const serviceUrl = 'Your_CData_API_Server_URL';
    
        fetch(serviceUrl + '/$metadata', { headers: { Authorization: authHeader } })
          .then(res => res.text())
          .then(text => {
            const parser = new DOMParser();
            const xml = parser.parseFromString(text, 'application/xml');
            const tables = [...xml.getElementsByTagName('EntityType')];
            const select = document.getElementById('tableSelect');
            tables.forEach(t => {
              const name = t.getAttribute('Name');
              const option = document.createElement('option');
              option.value = name;
              option.textContent = name;
              select.appendChild(option);
            });
            loadColumns(); // load columns for the first table
          });
    
        document.getElementById('tableSelect').addEventListener('change', loadColumns);
    
        function loadColumns() {
          const table = document.getElementById('tableSelect').value;
          fetch(serviceUrl + '/$metadata', { headers: { Authorization: authHeader } })
            .then(res => res.text())
            .then(text => {
              const parser = new DOMParser();
              const xml = parser.parseFromString(text, 'application/xml');
              const entity = [...xml.getElementsByTagName('EntityType')].find(t => t.getAttribute('Name') === table);
              const columns = [...entity.getElementsByTagName('Property')];
              const container = document.getElementById('columnsContainer');
              container.innerHTML = '';
              columns.forEach(col => {
                const name = col.getAttribute('Name');
                const div = document.createElement('div');
                div.innerHTML = `<label><input type="checkbox" value="${name}" checked> ${name}</label>`;
                container.appendChild(div);
              });
            });
        }
    
        function loadGrid() {
          const table = document.getElementById('tableSelect').value;
          const selectedCols = [...document.querySelectorAll('#columnsContainer input:checked')].map(i => i.value);
    
          const odata = new wijmo.odata.ODataCollectionView(serviceUrl, table, {
            requestHeaders: { Authorization: authHeader }
          });
    
          const grid = new wijmo.grid.FlexGrid('#theGrid', {
            itemsSource: odata,
            autoGenerateColumns: false,
            columns: selectedCols.map(col => ({ binding: col, header: col })),
            selectionMode: 'CellRange',
            allowSorting: true
          });
        }
    </script>
    
    </body>
    </html>
  6. Open the HTML file in your browser.
  7. Your browser should display the Wijmo FlexGrid. You can select a table and columns to display your data.

It's that simple. You can build even more complex applications and grids with Wijmo FlexGrid and the CData API Server by connecting to live data from PingOne.

Check out the various frameworks supported by Wijmo at https://developer.mescius.com/wijmo.


Start Your Free 30-Day Trial of CData API Server

Experience how easy it is to create live, flexible OData APIs for your Wijmo FlexGrid applications with a free 30-day trial of the CData API Server. Quickly connect to live data from PingOne and hundreds of other sources, enabling dynamic, real-time grids without manual data movement.

Start 30-Day Free Trial

Ready to get started?

Learn more or sign up for a free trial:

CData API Server