Links

Add BDK to an Extension App for Circle of Trust

Prerequisites

Complete the previous guide on building an extension app with app views
Complete the first part of this guide with the assistance of your pod administrator, ensuring that your app has the Primary User Identity and Trust application permissions.
This guide will use a shared extension app entry that is available for everyone to use on the developer sandbox. The app id is localhost-4000 and the RSA private key can be downloaded from this location. This entry expects that the app is hosted on https://localhost:4000 with the entrypoint controller.html at the root.

User Identity

In order to obtain identity information of the current user, an extension app needs to perform an authentication call and validation loop as part of the Circle of Trust process. This requires a backend service to call Symphony REST APIs so as to secure the required private key. You can choose to manually create your own REST API client and link the endpoint contracts to the ADK configuration, but this guide will demonstrate how to use BDK to ease the process.

Create BDK Project

$ yo @finos/symphony
__ __ ___ _
\ \ / /__ / __|_ _ _ __ _ __| |_ ___ _ _ _ _
\ V / _ \ \__ \ || | ' \| '_ \ ' \/ _ \ ' \ || |
|_|\___/ |___/\_, |_|_|_| .__/_||_\___/_||_\_, |
|__/ |_| |__/
Welcome to Symphony Generator v2.8.0
Project files will be generated in folder: /home/user/code/bdk-ext-app
______________________________________________________________________________________________________
? Enter your pod host develop2.symphony.com
? Enter your bot username my-bot
? Select your project type Extension App (BDK)
? Select your programing language Java
? Enter your app id localhost-4000
? Select your build system Maven
? Enter your project artifactId bot-application
? Enter your base package com.mycompany.bot

Configuration

As we won't be using the bot components, we can remove configuration relating to bots. We will also remove the TLS configuration as we will use ADK to host the frontend app instead. We also need to expand the CORS configuration as our frontend will make a cross-origin call to this backend in development mode (modify as appropriately for production).
src/main/resources/application.yaml
1
bdk:
2
host: develop2.symphony.com
3
app:
4
appId: localhost-4000
5
privateKey:
6
path: rsa/privatekey.pem
7
8
bdk-app:
9
auth:
10
enabled: true
11
cors:
12
"[/**]":
13
allowed-origins: "*"
14
allowed-headers: "*"
15
allowed-credentials: false
16
allowed-methods: [ "POST", "GET" ]
If you are using your own extension app id and key, change the values as appropriate. If you are using the developer sandbox, download this key into rsa/privatekey.pem.

Start Backend

Either launch the BDK project from your IDE or use the respective maven or gradle command:
# Maven
./mvnw spring-boot:run
# Gradle
./gradlew bootRun

Build ADK App

Modify the index.js or index.ts file from the earlier ADK project to be as follows:
index.ts
1
import * as ADK from '@symphony-ui/adk';
2
3
const backendUri = 'http://localhost:8080/bdk/v1/app';
4
5
const headers = {
6
'Accept': 'application/json',
7
'Content-Type': 'application/json'
8
};
9
10
const getAppToken = () => fetch(`${backendUri}/auth`, { method: 'POST' })
11
.then(r => r.json())
12
.then(r => r.appToken);
13
14
const validateAppToken = (appToken: string, symphonyToken: string) =>
15
fetch(`${backendUri}/tokens`, { method: 'POST', body: JSON.stringify({ appToken, symphonyToken }), headers })
16
.then(r => null);
17
18
const validateJwt = (jwt: string) =>
19
fetch(`${backendUri}/jwt`, { method: 'POST', body: JSON.stringify({ jwt }), headers })
20
.then(r => r.json());
21
22
const config : ADK.SymphonyAppDescriptor = {
23
id: 'localhost-4000',
24
circleOfTrust: { getAppToken, validateAppToken, validateJwt },
25
};
26
27
ADK.start(config).then(() => {
28
ADK.navigation.add('My App', () => ADK.modules.open('view-a', { title: 'Hello' }));
29
});
Note that we previously only supplied id to the ADK.start call but we now supply an additioinal circleOfTrust object in that configuration. This object has 3 properties that each return a promise.
  • getAppToken: calls the backend to perform app authentication and retrieve the token
  • validateAppToken: calls the backend to perform token validation
  • validateJwt: calls the backend to perform JWT validation
ADK takes care of adherence to the Circle of Trust process so you only need to define these contracts to allow ADK to perform the required backend calls.
Now that the app is authenticated, we can fetch user identity from either the controller or views. Let's edit the existing view to be as follows:
views/view-a.tsx
1
import * as React from 'react';
2
import * as ADKReact from '@symphony-ui/adk-react';
3
import * as ADK from '@symphony-ui/adk';
4
import { useEffect, useState } from 'react';
5
import './view-a.css';
6
7
const ViewA = () => {
8
const [ user, setUser ] = useState<ADK.UserJwt>();
9
10
useEffect(() => {
11
ADK.user.getUserInfo().then(response => setUser(response));
12
}, []);
13
14
return (
15
<div className="main-view">
16
<main>
17
{ user && (
18
<div>
19
<strong>User</strong>: {user.displayName} ({user.emailAddress})
20
</div>
21
)}
22
</main>
23
</div>
24
);
25
};
26
27
ADKReact.createView(<ViewA />, { id: 'localhost-4000' });

Start the App

We can now start the app using:
npm start

Load the App in Symphony

Instead of performing bundle injection as before, load Symphony normally now. Once Symphony is loaded, open the Marketplace using the left rail. Locate your App and install it. If you are using the developer sandbox, the app's name is Localhost 4000.

Test the App

Once the app is installed, you should notice a new app appears in the Apps section labelled as My App. If you launch the app, it opens a module showing the view, which contains your display name and email.
Last modified 1mo ago