Connected apps

Let one of your apps call another, even when it is private.

Connect two apps

Run this in the folder of the app that will be called, and name the app that will call it. Both must be your apps.

$ cd budget
$ shim connect reports
reports can now call budget at https://budget.shim.live

You can also add callers under "Apps that can call this app" in the app's Settings in the dashboard, or with the callers key in shim.toml.

Make the call

The calling app receives a variable named SHIM_APP_TOKEN automatically. It sends that value in the x-shim-app-token header:

const res = await fetch("https://budget.shim.live/api/totals", {
  headers: { "x-shim-app-token": process.env.SHIM_APP_TOKEN },
});

One token works for every app the caller is allowed to call.

Receive the call

The app being called receives the caller's name:

x-shim-caller: reports

Shim removes any x-shim- header the caller sends itself, so x-shim-caller can be trusted. These requests carry no x-shim-user header and no cookies.

A request with a missing or wrong token, or from an app that is not on the list, is treated like any other request: a private app answers 401.

List and remove

$ shim callers
$ shim disconnect reports

An app can have up to 50 callers.

Replace a token

If an app's token may have leaked, run this in that app's folder. The old token stops working within a minute, and the app restarts with a new one. Every app it could call still accepts it.

$ shim rotate-token