Quickstart

Issue `user_token`

Give the product client a user-scoped credential that can call the Federation.

user_token is issued by Federation through a trusted flow. Your backend uses FederationAdmin to request a token based on bureau_id + user_id.

import { FederationAdmin } from "@downcity/federation/legacy";

const admin = new FederationAdmin({
  base_url: "https://base.example.com",
  credential: administrator_session_token,
});

const user = await admin.service("accounts").action("tokens/issue").invoke({
  bureau_id: "demo",
  user_id: "user_123",
  metadata: {
    plan: "pro",
  },
  ttl: "7d",
});

Return user.user_token to the product. The Token already contains bureau_id, so normal service requests do not submit it again.

What metadata is for

metadata carries business context such as plan or organization into hooks:

const action = service.action("generate", async (ctx) => {
  return generateSomething(ctx.input);
});

action.before(async (ctx) => {
  await quotaService.check({
    bureau_id: ctx.bureau?.bureau_id,
    user_id: ctx.user?.user_id,
    plan: ctx.user?.metadata?.plan,
  });
});

This is how multiple product clients share one auth and quota layer cleanly.

Table of Contents