Federation User
Federation User
A Federation user session owns identity, permissions, and Credits. Sign in by selecting a Federation and Provider, or supply an existing user_token.
import { Federation } from "@downcity/federation";
const federation = new Federation({ url: "https://fed.example.com" });
const providers = await federation.user.account.providers();
await federation.user.account.login({
provider: "email", client_type: "cli",
input: { email: "[email protected]", password: "password" },
});
const current_user = await federation.user.current();
const result = await federation.user.service("rewrite").action("formal").invoke({ text: "hello" });Verify an email before signing in. login() exchanges the completed flow and updates the user credential; status() only returns progress. await federation.user.account.logout() revokes the token before clearing it, preserving credentials on failure for retry. Federation validates signature, issuer, audience, expiry, and revocation. Admin Sessions remain separate from User Tokens.
City model and Power requests automatically carry the locally persisted city_id. Direct user requests may omit it. Independent callers can use federation.user.with_city("city_product") to create a source view. Source labels are recorded for logs, usage, and jobs and grant no permission. Use user.service(name) for business requests to the current Federation.
OAuth requires random state, S256 PKCE, and a single exchange. Website callbacks must exactly match server trusted_web_callbacks; an empty list rejects web OAuth. CLI/Desktop use an exclusive local 127.0.0.1 callback receiver. See account sign-in.