Keep data in the EU
Create the organization in the EU region and point every SDK at it.
What it shows
- You create the organization in the EU region, at
https://eu.app.lumoauth.dev. - Each SDK and the CLI get the EU address where you create the client.
- A program gets a token, and the issuer of the token starts with the EU address.
The two regions are separate deployments, and nothing is copied between them. An organization belongs to the region where you created it, and you cannot move it later. Its users, sessions, applications, audit logs and signing keys stay in that region.
Before you start
- An organization in the EU region. On the sign-up page, choose European Union under Data region.
- An API key of that organization, created in its portal under Applications & developer tools, API keys. An API key of a US organization does not work in the EU region.
- The setup script registers an agent, "EU invoice archiver", and prints its client ID and secret.
| Variable | Value |
|---|---|
LUMOAUTH_URL | https://eu.app.lumoauth.dev, the address of the EU region. The programs use it when the variable is not set. |
LUMOAUTH_ORG_ID | Your organization, for example acme-corp. |
LUMOAUTH_API_KEY | For the setup script: an API key with the scopes admin:agents:read and admin:agents:write. The CLI script uses it too, and its check of the Admin API needs admin:settings:read. |
AGENT_CLIENT_ID | The client ID of the agent. The setup script prints it. |
AGENT_CLIENT_SECRET | The client secret of the agent. The setup script prints it once. |
The setup script creates what the recipe needs, through the Admin API. You can run it again at any time.
node b2b/eu-region/setup.mjs
setup.mjs
// Registers the agent of this recipe in your organization, with a client ID
// and secret. The programs use it to get a token. Run it again at any time.
//
// LUMOAUTH_URL=https://eu.app.lumoauth.dev node b2b/eu-region/setup.mjs
//
// The API key needs the scopes admin:agents:read and admin:agents:write.
import { call, ensure, printEnv, url } from '../../_lib/admin.mjs';
const agent = await ensure('/admin/agents', (a) => a.name === 'EU invoice archiver', {
name: 'EU invoice archiver',
description: 'Stores the invoices of European customers in the EU region.',
identityType: 'client_secret',
capabilities: ['invoices:read'],
});
// LumoAuth shows a secret once, in the answer that creates it. On a second
// run the script therefore asks for a new secret, and the old one stops.
const secret =
agent.clientSecret ??
(await call('POST', `/admin/agents/${agent.agentId}/rotate-credentials`)).data.clientSecret;
console.log(`Agent "${agent.name}" is ready at ${url}.`);
printEnv({ AGENT_CLIENT_ID: agent.agentId, AGENT_CLIENT_SECRET: secret });
Code
Each program reads the address from LUMOAUTH_URL and uses the EU address when the variable is not set. It passes the address to the SDK in the option for it: baseUrl in JavaScript, base_url in Python, BaseURL in Go, and LUMO_BASE_URL for the CLI.
Run each command from the recipes folder of the examples repository. Set the folder up once for your language. Every version below was run against a LumoAuth organization. The programs ran against an organization at another address, which LUMOAUTH_URL named. They make the same requests to the EU address.
- Node.js
- Python
- Go
- lumo CLI
// Points the agent SDK at the EU region, gets a token, and checks its issuer.
//
// node b2b/eu-region/js/region.mjs
import { LumoAgent, decodeJwt } from '@lumoauth/agent';
// The EU region has its own address. An organization exists in one region
// only, so the address and the organization belong together. The other
// clients take the same option: `baseUrl` in LumoAuthBackend and in
// @lumoauth/client.
const baseUrl = process.env.LUMOAUTH_URL ?? 'https://eu.app.lumoauth.dev';
// Reads LUMOAUTH_ORG_ID, AGENT_CLIENT_ID and AGENT_CLIENT_SECRET.
const agent = new LumoAgent({ baseUrl });
console.log(`server: ${baseUrl}`);
// The issuer of the token names the region that signed it.
const token = await agent.authenticate();
console.log(`issuer: ${decodeJwt(token).claims.iss}`);
node b2b/eu-region/js/region.mjs
"""Point the agent SDK at the EU region, get a token, and check its issuer.
python b2b/eu-region/python/region.py
"""
import os
import jwt
from lumoauth import LumoAuthAgent
# The EU region has its own address. An organization exists in one region
# only, so the address and the organization belong together. The client for
# your backend, LumoAuth, takes the same argument, `base_url`.
base_url = os.environ.get("LUMOAUTH_URL", "https://eu.app.lumoauth.dev")
# Reads LUMOAUTH_ORG_ID, AGENT_CLIENT_ID and AGENT_CLIENT_SECRET.
agent = LumoAuthAgent(base_url=base_url)
print(f"server: {base_url}")
# The issuer of the token names the region that signed it. The program only
# reads the claim: the API that receives the token checks the signature.
if not agent.authenticate():
raise SystemExit("The agent could not get a token. Check AGENT_CLIENT_ID and AGENT_CLIENT_SECRET.")
claims = jwt.decode(agent.access_token, options={"verify_signature": False})
print(f"issuer: {claims['iss']}")
python b2b/eu-region/python/region.py
// Points the agent SDK at the EU region, gets a token, and checks its issuer.
//
// go run ./b2b/eu-region/go
package main
import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"log"
"os"
"strings"
lumoauth "github.com/lumoauth/lumo-auth-go"
)
func main() {
// The EU region has its own address. An organization exists in one region
// only, so the address and the organization belong together. The client
// for your backend takes the same address: lumoauth.New(lumoauth.WithBaseURL(baseURL)).
baseURL := os.Getenv("LUMOAUTH_URL")
if baseURL == "" {
baseURL = "https://eu.app.lumoauth.dev"
}
// Reads LUMOAUTH_ORG_ID, AGENT_CLIENT_ID and AGENT_CLIENT_SECRET.
agent, err := lumoauth.NewAgent(lumoauth.AgentConfig{BaseURL: baseURL})
if err != nil {
log.Fatal(err)
}
fmt.Printf("server: %s\n", baseURL)
// The issuer of the token names the region that signed it. The program
// only reads the claim: the API that receives the token checks the signature.
token, err := agent.Authenticate(context.Background())
if err != nil {
log.Fatal(err)
}
parts := strings.Split(token, ".")
if len(parts) != 3 {
log.Fatal("the token is not a JWT")
}
payload, err := base64.RawURLEncoding.DecodeString(parts[1])
if err != nil {
log.Fatal(err)
}
var claims struct {
Iss string `json:"iss"`
}
if err := json.Unmarshal(payload, &claims); err != nil {
log.Fatal(err)
}
fmt.Printf("issuer: %s\n", claims.Iss)
}
go run ./b2b/eu-region/go
#!/bin/sh
# Point the lumo CLI at the EU region, and check the issuer, with jq.
#
# sh b2b/eu-region/cli/region.sh
set -eu
# The CLI reads the address from LUMO_BASE_URL. A profile can keep it instead:
# lumo profile create acme-eu --org acme-corp --base-url https://eu.app.lumoauth.dev --use
export LUMO_BASE_URL="${LUMOAUTH_URL:-https://eu.app.lumoauth.dev}"
export LUMO_ORG="$LUMOAUTH_ORG_ID" LUMO_API_KEY="$LUMOAUTH_API_KEY"
# `lumo doctor` reads the discovery document of the organization and makes one
# call to the Admin API. The issuer in the discovery document is the `iss` of
# every token of the organization.
lumo doctor -o json | jq -r '.checks[]
| select(.name == "server" or .name == "discovery")
| if .name == "server" then "server: \(.detail)" else "issuer: \(.detail | sub("^issuer "; ""))" end'
sh b2b/eu-region/cli/region.sh
Check the result
server: https://eu.app.lumoauth.dev
issuer: https://eu.app.lumoauth.dev/orgs/acme-corp/api/v1
- The
issclaim of every token of the organization starts withhttps://eu.app.lumoauth.dev. An API that checks the issuer accepts only tokens of this region. - In a browser app, the address goes into the
domainprop of the provider. See Install the React components. - With the CLI,
lumo loginasks for the region. A profile keeps the address, so that one machine can work with an organization in each region.
Limits
- An organization cannot change its region. To move, create an organization in the other region and move the users and settings yourself.
- Mail, text messages and AI requests can leave the region, depending on the providers that you choose. The data residency page lists each one, and what to set for a flow that stays in the EU.
- Your own application must also keep its data in the EU. LumoAuth controls only the data that it stores.