Trax Platform APIv1

Authentication and keys

Every endpoint declares who may call it. The reference shows it as Access on each operation.

Access Who How
Public Anyone No credentials. Public data only: catalog, configuration, content.
Site key A registered website, from the browser X-Trax-Site-Key: pk_… header (optional on public endpoints today).
Site secret A registered website's server side, such as Duda collections Authorization: Bearer sk_…, or ?key=sk_… where headers can't be set.
Family A signed-in parent or guardian Authorization: Bearer … with an access token from family sign-in (OpenID Connect).
Staff Organization staff in the organization site Authorization: Bearer … with a Trax staff (Keycloak) access token for the organization site.
nFocus admin nFocus support in the admin app Authorization: Bearer … with a Trax staff (Keycloak) access token for the admin app. Every call is audited.
Service nFocus systems Authorization: Bearer … with an OAuth client-credentials token.

Site keys

Each registered website (usually a Duda site) is bound to one portal and has two keys:

A wrong or revoked key returns 401 invalid-site-key. A key for another portal returns 403 site-key-mismatch, and a browser call from an unregistered origin returns 403 origin-not-allowed.

Calling with a publishable site key

GET https://api.nfocus.solutions/v1/portals/riverbend/north/config → 200 OK, JSON

curl
curl -s 'https://api.nfocus.solutions/v1/portals/riverbend/north/config' \
  -H 'X-Trax-Site-Key: pk_your_publishable_key'
JavaScript
const response = await fetch('https://api.nfocus.solutions/v1/portals/riverbend/north/config', {
  headers: {
    'X-Trax-Site-Key': 'pk_your_publishable_key',
  },
});
const data = await response.json();
C#
using var http = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.nfocus.solutions/v1/portals/riverbend/north/config");
request.Headers.Add("X-Trax-Site-Key", "pk_your_publishable_key");
using var response = await http.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();

Browsers and CORS

Cross-origin browser calls are allowed only from registered site origins and nFocus's own front ends. Other origins get no CORS headers, so browsers block their requests. Credentials are never cookies: browser callers send a site key or, once family sign-in arrives, a bearer token.

Family sign-in

Families sign in on the API's own pages, branded for each organization, with the email and password they already use for Trax Online Registration. The legacy portal keeps working with the same accounts. Websites and apps use OpenID Connect, authorization code with PKCE (S256). They redirect to the API, the API sends the family back with a code, and the site redeems the code for tokens. A website never sees a password.

The API is its own issuer. Any standard OpenID Connect client library can read its settings from the discovery document:

OpenID Connect discovery

GET https://api.nfocus.solutions/.well-known/openid-configuration → 200 OK, JSON

curl
curl -s 'https://api.nfocus.solutions/.well-known/openid-configuration'
JavaScript
const response = await fetch('https://api.nfocus.solutions/.well-known/openid-configuration');
const data = await response.json();
C#
using var http = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.nfocus.solutions/.well-known/openid-configuration");
using var response = await http.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();

Clients

Client client_id Redirect URI Portal
A Duda site site-{clientToken}-{orgToken} (one per site) {site origin}/callback, for each registered origin Fixed: the site's own portal
The new Online Registration front end trax-olr Registered per environment Named on each request: portal=riverbend/north

Clients are public: no client secret, so PKCE is required. The API never redirects to an address the client didn't register. A site client that asks for another portal gets error=invalid_request back on its redirect URI.

The flow

  1. Send the browser to /connect/authorize with client_id, redirect_uri, response_type=code, scope=openid profile email offline_access, state, code_challenge and code_challenge_method=S256 (plus portal for trax-olr).
  2. The family signs in on /account/{clientToken}/{orgToken}/sign-in. A family already signed in at that client isn't asked again. Use prompt=none to check silently; it returns error=login_required when nobody is signed in.
  3. The API redirects to redirect_uri with code and your state.
  4. POST /connect/token (form-encoded) with grant_type=authorization_code, client_id, redirect_uri, code and code_verifier. Codes work once, within 2 minutes.
  5. Call the API with Authorization: Bearer {access_token}:

The signed-in family's account

GET https://api.nfocus.solutions/v1/portals/riverbend/north/me → 200 OK, JSON

curl
curl -s 'https://api.nfocus.solutions/v1/portals/riverbend/north/me' \
  -H 'Authorization: Bearer your_access_token'
JavaScript
const response = await fetch('https://api.nfocus.solutions/v1/portals/riverbend/north/me', {
  headers: {
    'Authorization': 'Bearer your_access_token',
  },
});
const data = await response.json();
C#
using var http = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.nfocus.solutions/v1/portals/riverbend/north/me");
request.Headers.Authorization = new("Bearer", "your_access_token");
using var response = await http.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();

Tokens

Token Lifetime Notes
Access token 10 minutes A signed JWT for audience trax-api. sub is the login; trax_db and trax_org name the client database and portal organization.
Identity token 10 minutes Name (profile scope) and email (email scope), for your own display.
Refresh token 12 hours from sign-in With offline_access. Each use returns a new one with the same expiry, so refreshing never extends the session; after 12 hours the family signs in again. A used one stops working shortly after.

A family has one login per Trax client, so a token from one of a client's portals works on its other portals. On another client's portal it is refused:

A family token on another client's portal

GET https://api.nfocus.solutions/v1/portals/harbor/lakeside/me → 401, problem details

curl
curl -s 'https://api.nfocus.solutions/v1/portals/harbor/lakeside/me' \
  -H 'Authorization: Bearer your_access_token'
JavaScript
const response = await fetch('https://api.nfocus.solutions/v1/portals/harbor/lakeside/me', {
  headers: {
    'Authorization': 'Bearer your_access_token',
  },
});
const data = await response.json();
C#
using var http = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.nfocus.solutions/v1/portals/harbor/lakeside/me");
request.Headers.Authorization = new("Bearer", "your_access_token");
using var response = await http.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();

Changing the password, a reset, or a lockout ends every refresh token for the login. Sign out with /connect/endsession.

The hosted account pages

Link to these directly when it helps. Each one is branded for the portal.

Page Path
Sign in /account/{clientToken}/{orgToken}/sign-in
Create an account /account/{clientToken}/{orgToken}/sign-up
Forgot password /account/{clientToken}/{orgToken}/forgot-password (?email= fills in the address)

Organization staff (the organization site)

Staff sign in to the organization site with their Trax staff account (Keycloak). The API accepts Keycloak access tokens issued for audience trax-site-manager that carry a verified email address. A token without a verified email gets 403 email-not-verified. Staff hold a role for each site: Site Admin, Editor or Author. nFocus support staff can see every site.

The signed-in staff user and their sites

GET https://api.nfocus.solutions/v1/manage/me → 200 OK, JSON

curl
curl -s 'https://api.nfocus.solutions/v1/manage/me' \
  -H 'Authorization: Bearer your_keycloak_access_token'
JavaScript
const response = await fetch('https://api.nfocus.solutions/v1/manage/me', {
  headers: {
    'Authorization': 'Bearer your_keycloak_access_token',
  },
});
const data = await response.json();
C#
using var http = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Get, "https://api.nfocus.solutions/v1/manage/me");
request.Headers.Authorization = new("Bearer", "your_keycloak_access_token");
using var response = await http.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();

In local development the API trusts a synthetic Keycloak realm at http://localhost:8180/realms/TraxSolutions (dotnet run --project tools/Trax.Platform.DbTool -- keycloak).

nFocus admin

The admin app's tokens come from the same Keycloak realm for audience trax-admin, so they work only under /v1/admin, and organization site tokens don't work there. Realm role trax-support may do everything, trax-support-agent only read. See nFocus admin.

Service clients

nFocus systems call /internal/v1/… with a client-credentials token: POST /connect/token with grant_type=client_credentials, the client id and secret, and scope=trax.internal. Family and staff tokens are refused there.

Local development

Seeded families sign in with the password in your .env (DbTool__SeedUserPassword). Account emails wait in the TraxPlatform outbox until the worker sends them. Locally the worker sends to Mailpit, and its inbox is at http://localhost:8035. Without the worker, this command shows the latest emails with their links: dotnet run --project tools/Trax.Platform.DbTool -- outbox --env dev.