How to extend OpenDAX stack with your own application?

Artem Linetskyi
Openware
4 min readSep 24, 2019

--

In this tutorial, we’re going to create a custom application and integrate it into OpenDAX Crypto exchange platform on a simple docker-compose solution.

Before you continue, familiarize with OpenDAX and run it locally.

Before we create the app we need to understand how the authorization and sharing session works. Barong uses JWT for managing authorization.

An authorization flow diagram is presented below:

On successful user login, a cookie will be set. After that, this cookie is attached to each request. Every given request is first routed to Barong, where cookie gets validated and transformed into JWT signed by Barong. This JWT is then routed to each respective component. The recipient component (e.g. Peatio or any app) needs to validate the JWT and check the signature.

After JWT is decoded, the app has access to this object.

An already working example can be found here

For this tutorial, we’re going to extend Rubykube API with another component written in Node js. This is a simple component that will share the session with barong and return a user email from barong JWT on /api/users/me

  1. Create a new Express app:

2. Create an example Server:

Simple server file app.js

3. Integrate it in opendax and test

  • Create a Dockerfile for our app and build image

docker build -t myapp:test .

  • Create a compose entry in opendax

Let’s change our directory to opendax

Append the following block to templates/compose/app.yaml.erb , by doing so we’ve created a new service called myapp. Make sure that indentation is correct.

  • Create an env file for our app

Let’s create a file templates/config/myapp.env.erb , be aware of the name, because we reference it in compose file. This file should be created in the templates folder as it will get rendered by opendax.

BARONG_JWT_PUBLIC_KEY=<%= @jwt_public_key %>

This is the only line we need.

  • Reference our app docker image in opendax/config/app.yml
  • Add our application to envoy configuration

Open templates/config/gateway/envoy.yml.erb

  • Run the application

We need to bring up all the stack to test our app:

rake service:all

Now, let’s deploy our app:

docker-compose up -Vd myapp

  • Test deployed application

For easier testing let’s install httpie

After installing httpie we’re going to create a session for a user and test our application

  • Add an entry to /etc/hosts
    Add this line to the file, to be able to access our application on one hostname
  • Create a session
  • Test our application

CONGRATULATIONS! We’ve successfully developed our custom component for OpenDAX solution. Now the sky is the only limit.

Useful links:

https://github.com/openware/nodelogic
https://github.com/openware/opendax
https://github.com/openware/node-auth-barong
https://www.openware.com/
https://rubykube.io/

Originally published at https://github.com.

--

--

Artem Linetskyi
Openware

Software developer who likes to cook, travel and be his true self. Follow me here: https://www.alinetskyi.com/