FlowPrime guides

Auth: sign people in to your product, with teams, seats and hosted screens

Auth (ALKEYON) is the identity service of your workspace. It hosts every sign-in screen (sign-in, sign-up, e-mail verification, password reset, two-factor, invitation acceptance, the team page) under your brand, and hands your app a signed token that says who the person is and which one company they act for. Every product that has a login needs it, and almost every product needs two sign-in apps: one for your own team and one for your customers.

What you can do

Capability How Status
Register a sign-in app for your team or your customers auth_create_oidc_app live
Change an app in place (redirect URIs, scopes, PKCE, sign-up rules, sign-up flags) auth_update_oidc_app live
List, rotate the secret of, revoke and delete apps auth_list_oidc_apps, auth_rotate_oidc_secret, auth_revoke_oidc_app, auth_delete_oidc_app live
Sign people in (OIDC authorization code + PKCE, refresh tokens, userinfo) REST: the endpoints in your discovery document live
Your workspace's sign-in endpoints (issuer, discovery, token, jwks, logout...) endpoints in auth_get_org and auth_create_oidc_app live
Sign a person out: revoke a refresh token, hosted sign-out revocation_endpoint, end_session_endpoint in discovery live
Public sign-up form, extra sign-up fields (CPF, CNPJ, phone, regex), work e-mail only allowSelfRegistration, signupProfile on the app live
A free customer workspace when a sign-up verifies its e-mail signupGrantsAccount + freeTier on the app live
A customer workspace born from a purchase the payments pipeline writes the grant; see platform_guide topic=payments live
"Subscribe" button on the refusal page for people with no workspace checkoutUrl on the app live
Customer teams: owner invites colleagues, removes seats hosted Team page; REST GET/POST /v1/orgs/{org}/accounts/mine... with the customer's own token live
One person in several customer companies (switcher) hosted account chooser at sign-in live
Your own team: add, remove, re-role, reset password, resend verification auth_add_org_member, auth_remove_org_member, auth_set_member_role, auth_send_member_reset, auth_resend_member_verification live
Read who changed what auth_list_org_activity live
Count customer accounts and seats, read their account ids auth_list_customer_accounts live
Read when your customers signed in auth_list_customer_signins live
API keys (ffk_...) for server-to-server calls auth_create_api_key live
Two-factor sign-in (TOTP, recovery codes), set up by each person hosted screens live
Require two-factor for your whole workspace dashboard, Developers > Sign-in > Security dashboard
Sign in with Google, Microsoft or GitHub dashboard, Developers > Sign-in > Security (shows the callback address to register with each provider) dashboard
Your logo, colours and fonts on every hosted screen dashboard, Developers > Sign-in > Look and language dashboard
Consumer app: every no-seat customer lands in one account you own (account_role consumer) consumerAccountId on auth_create_oidc_app; change or remove it later with auth_update_oidc_app (an empty string removes it) live (it needs the id of an account you own: auth_list_customer_accounts lists every customer account with its accountId and owner)
A machine client pinned to one customer seat (an ERP connecting with client credentials) serviceUserId + serviceAccountId on auth_create_oidc_app or auth_update_oidc_app (empty strings for both remove it); dashboard: Developers > Sign-in > Apps, the app's Settings tab, Machine access live (both ids come from auth_list_customer_accounts)
That machine acting on behalf of another member of the same customer account (a person picked per request) actsForAccountMembers=true on auth_update_oidc_app, then on_behalf_of=<user id or e-mail> on the client credentials request; dashboard: the app's Settings tab, Machine access live (only members of the pinned account; see "A customer's machine")
AI assistants connecting to your FlowPrime MCP, or to your product's own MCP server dynamic client registration on your org issuer live

Before you start

Two surfaces: team and customer

Every sign-in app has a surface, and it decides who may come in and what the token carries.

A team account cannot sign in to a customer app on the strength of being staff. Staff roles stay off customer tokens by design, so the admin who created the workspace opens the customer app and is refused with no_seat ("You don't have a seat here yet"). To test as a customer, do one of these:

  1. Use a second e-mail address and sign up (or buy) through the customer app like any customer.
  2. Give your own e-mail a seat in a customer account. A seat comes only from a purchase (or a free-tier sign-up grant), which makes you the owner of a new account, or from an account owner's invitation, which you accept. Staff keep their team role when they take a seat; the customer token simply shows the seat.

Most products need both apps: a customer app for the product itself and a platform app for the team's admin side. surface defaults to platform when you leave it out, so always pass it.

Identity shapes

Pick the shape from one question: does more than one person ever need to see the same records? If yes, customers need a company (an account with seats). If never, they are consumers.

Shape surface allowSelfRegistration signupGrantsAccount / freeTier checkoutUrl Notes
Checkout-first, with teams customer false false your pricing or buy page The purchase writes a grant; the first sign-in creates the account and seats the buyer as owner. No junk logins.
Sign up, then buy customer true false your buy page A bare login holds nothing; it is refused no_seat with a Subscribe button until they buy.
Free tier customer true true / default_plan or trial_grant optional Verifying the e-mail earns one free owned account per e-mail, ever. Upgrading changes the plan on the same account.
Consumer app customer true false - Needs consumerAccountId at creation. Each person gets account_role consumer on your account; your app partitions by sub.
Paid consumer app customer false false your buy page Same as consumer app, closed: people get in by paying at your checkout. Needs consumerAccountId at creation.
Internal tool platform false false - Your staff sign in with their team role. For a closed group of outsiders, use customer and seat them by invitation into an account you own.

Other app settings:

Step by step

Register the customer app

  1. auth_get_org to read {org}.
  2. auth_create_oidc_app with name, surface: "customer", redirectUris: "[\"https://app.example.com/auth/callback\"]", scopes: "openid profile email org", grantTypes: "authorization_code,refresh_token", isFirstParty: true, requirePkce: true, and the shape flags from the table (allowSelfRegistration, signupGrantsAccount, freeTier, checkoutUrl, signupProfile).
  3. Store the returned clientId and clientSecret in your app's secrets. The secret is shown once; auth_rotate_oidc_secret issues a new one and kills the old one immediately.
  4. Configure your client from the endpoints the answer carries (the same as auth_get_org): discovery is the document to read, and issuer is what your tokens' iss will be.
  5. Change any setting later with auth_update_oidc_app (it takes the application id, not the client id). Only what you pass changes.

Register the team app

Same as above with surface: "platform", allowSelfRegistration false, and the redirect URI of your admin console. Add teammates with auth_add_org_member (member or org_admin; you grant at most your own role). For an address already in your organization it replaces that person's role, an org_admin included, so read them with auth_get_org_member first and change a role on purpose with auth_set_member_role. It sends no welcome mail: a new teammate sets their password through Forgot password.

Sign in (authorization code + PKCE)

Minimal FastAPI app (pip install fastapi uvicorn authlib httpx itsdangerous):

import os
import httpx
from urllib.parse import urlencode
from fastapi import FastAPI, Request
from fastapi.responses import RedirectResponse, HTMLResponse
from starlette.middleware.sessions import SessionMiddleware
from authlib.integrations.starlette_client import OAuth, OAuthError

ORG = os.environ["FLOWPRIME_ORG"]                       # your workspace slug
DISCOVERY_URL = os.environ["DISCOVERY_URL"]  # auth_get_org endpoints.discovery; never build it by hand
APP_URL = os.environ["APP_URL"]                         # e.g. https://app.example.com

app = FastAPI()
app.add_middleware(SessionMiddleware, secret_key=os.environ["SESSION_SECRET"],
                   https_only=True, same_site="lax")

oauth = OAuth()
oauth.register(
    "flowprime",
    client_id=os.environ["CLIENT_ID"],
    client_secret=os.environ.get("CLIENT_SECRET"),      # leave unset for a public client
    server_metadata_url=DISCOVERY_URL,
    client_kwargs={"scope": "openid profile email org", "code_challenge_method": "S256"},
)

def roles(claims):
    r = claims.get("org_role") or []
    return [r] if isinstance(r, str) else r

@app.get("/login")
async def login(request: Request):
    # authlib creates state, nonce and the PKCE verifier and keeps them in the session
    return await oauth.flowprime.authorize_redirect(request, f"{APP_URL}/auth/callback")

@app.get("/auth/callback")
async def callback(request: Request):
    try:
        token = await oauth.flowprime.authorize_access_token(request)  # checks state, PKCE, id_token
    except OAuthError as e:
        # a refusal at the token step reads e.g. "no_seat: the user holds no seat ..."
        return HTMLResponse(f"Sign-in refused: {e.description}", status_code=403)
    c = token["userinfo"]
    request.session["user"] = {k: c.get(k) for k in
        ("sub", "email", "name", "org_slug", "org_role", "account", "account_role")}
    # keep token["refresh_token"] server-side if you call APIs on the user's behalf
    return RedirectResponse("/")

@app.get("/")
async def home(request: Request):
    u = request.session.get("user")
    if not u:
        return RedirectResponse("/login")
    if u.get("account_role") == "consumer":
        return {"view": "my records", "filter": {"owner_sub": u["sub"]}}       # partition by person
    if u.get("account_role") in ("owner", "member"):
        return {"view": "company", "account": u["account"], "is_owner": u["account_role"] == "owner"}
    if f"{ORG}:org_admin" in roles(u):
        return {"view": "admin console"}                                       # team app
    return {"view": "team member"}

@app.get("/logout")
async def logout(request: Request):
    disc = httpx.get(DISCOVERY_URL).json()
    if refresh := request.session.get("refresh_token"):   # kept server-side only
        httpx.post(disc["revocation_endpoint"], data={"token": refresh, "token_type_hint": "refresh_token"},
                   auth=(os.environ["CLIENT_ID"], os.environ.get("CLIENT_SECRET", "")))
    request.session.clear()
    return RedirectResponse(disc["end_session_endpoint"] + "?" + urlencode({"post_logout_redirect_uri": f"{APP_URL}/"}))

What a person may do inside a customer account (admin, editor, viewer) is your app's own data, keyed by account and sub. Never derive it from account_role beyond the first sight: owner holds the plan and the bill, not your app's permissions.

Validate tokens in your API (do not skip a step)

Every request your API receives with Authorization: Bearer <token> must pass ALL of these, in this order:

  1. Signature: RS256, with the keys at jwks_uri from the discovery document. Cache the keys and fetch them again when a token names an unknown kid.
  2. Issuer and time: iss equals the discovery document's issuer (read it, never assume it is your workspace's host); exp is in the future (allow about 30 seconds of clock skew).
  3. Your workspace: org_slug equals YOUR workspace slug (and org_id your workspace id). This is the check that keeps other workspaces out: the signing keys, and for some workspaces the issuer, are shared across FlowPrime, so a valid signature alone does NOT prove the token is yours. Do not rely on aud for this either: it is not a per-workspace guarantee.
  4. The right kind of person for the route:
  5. The app it was issued to (when your API serves more than one app): azp equals the client id of the app this route belongs to. Every token minted through an app carries it: a person's token names the app they signed in to, and a backend token from client credentials names its own client (it also carries app_id, app_name and org_role <your-slug>:service). A token from the hosted pages themselves names no app and has no azp.
  6. What they may do: decide from your own records (the account's plan, the seat's role in your app), never from the fact that a token exists.

Two customer apps of the same workspace sign in the same people: azp tells their tokens apart, so an API for one app refuses the other app's tokens by checking it. If two populations must not cross (companies and independent cleaners, say), also separate them by data: each customer account has its own plan, so gate the company features on that account's plan (license_customer_entitlements, or the entitlements API in platform_guide topic=payments), and gate team routes on org_role.

FastAPI with PyJWT:

import os, httpx, jwt
from fastapi import Depends, Header, HTTPException

ORG = "your-workspace"  # production host below; on staging it is {ORG}.alkeyon.fastflowtech.ai
DISCOVERY = httpx.get(os.environ["DISCOVERY_URL"]).json()  # from auth_get_org endpoints.discovery
JWKS = jwt.PyJWKClient(DISCOVERY["jwks_uri"])
APP_CLIENT_ID = os.environ.get("APP_CLIENT_ID")  # set it when this API serves one app only

def claims(authorization: str = Header(...)) -> dict:
    token = authorization.removeprefix("Bearer ").strip()
    try:
        key = JWKS.get_signing_key_from_jwt(token).key
        c = jwt.decode(token, key, algorithms=["RS256"], issuer=DISCOVERY["issuer"], leeway=30,
                       options={"verify_aud": False, "require": ["exp", "iss", "sub"]})
    except jwt.PyJWTError:
        raise HTTPException(401, "invalid token")
    if c.get("org_slug") != ORG:
        raise HTTPException(401, "token from another workspace")
    if APP_CLIENT_ID and c.get("azp") != APP_CLIENT_ID:
        raise HTTPException(401, "token issued to another app")
    return c

def customer(c: dict = Depends(claims)) -> dict:
    if not c.get("account") or c.get("account_role") not in ("owner", "member", "consumer"):
        raise HTTPException(403, "customer route")
    return c

def team(c: dict = Depends(claims)) -> dict:
    roles = c.get("org_role") or []
    roles = [roles] if isinstance(roles, str) else roles
    if c.get("account") or not any(r in (f"{ORG}:org_admin", f"{ORG}:member") for r in roles):
        raise HTTPException(403, "team route")
    return c

Logout and revocation: what is and is not immediate

Call FlowPrime from your backend (client credentials)

Your product's server calls other FlowPrime services with a token of its own, not a person's. Each service's guide says whether it takes this token (ai and marketing do; analytics ingest does not yet).

  1. Once: auth_create_oidc_app name="<Product> backend" surface=platform grantTypes=client_credentials. The client secret is shown once: keep the client id and secret as server secrets, never in a browser. To call payments (reseller: payees, bookings, payouts) add scopes=api to the app (or later auth_update_oidc_app scopes=api); without it those calls answer 403. The token request itself needs no scope: the token carries the app's scopes.
  2. Read the token URL from endpoints in auth_get_org (or token_endpoint from the discovery document).
  3. POST to it, form-encoded: grant_type=client_credentials&client_id=...&client_secret=.... The access_token lasts expires_in seconds (60 minutes): cache it and fetch a new one shortly before it expires.
  4. Send it as Authorization: Bearer <token> to the service's API (service_contract service=<name> gives the exact routes).

A customer's machine (an ERP, an integration) and acting on behalf of someone

When one of your CUSTOMERS connects a system of theirs to your product with no person signing in, the system uses a customer app's client credentials. Its token must name the customer account it works for, so the app is pinned to one seat of that account:

  1. A customer app with grantTypes=client_credentials. Read the account and the person: auth_list_customer_accounts (the accountId, and members[].userId).
  2. auth_update_oidc_app appId=... serviceUserId=<userId> serviceAccountId=<accountId>. From then on, grant_type=client_credentials returns a token that is that person, in that account (sub, account, account_role), plus grant_type=client_credentials and the app's app_id. Without the pin the request is refused with no_seat. If the person leaves the account, it is refused again until you pin someone else.
  3. Optional, acting on behalf of another member: auth_update_oidc_app appId=... actsForAccountMembers=true. Then the machine may add on_behalf_of=<user id or e-mail> to its token request. The token is that member's (their sub, e-mail and account_role, in the same account) and carries act: {"sub": "<the app's client id>"}, so your API can record "done by the ERP for Ana". Every such token is written to the workspace activity log (auth_list_org_activity, event machine_on_behalf).
  4. Refusals, answered 400 with the reason: on_behalf_not_allowed (the app has actsForAccountMembers off) and not_in_account (the person is not a member of the pinned account). There is no way to act for anyone outside that account.

In your API, treat a token with act as the person it names: their role applies. Show the act app wherever you show who did something.

Customer teams

The owner of a customer account invites colleagues from the hosted Team page (https://{org}.alkeyon.fastflow.tech/Account/Team) or your app calls POST /v1/orgs/{org}/accounts/mine/invites with {"email": ...} using the owner's own access token. A person is seated only when they accept. GET /v1/orgs/{org}/accounts/mine returns the roster. Removing a seat stops that person's refreshes at once (an access token already issued runs to its expiry, about 15 minutes).

API keys

auth_create_api_key mints an ffk_... key for you in the workspace, shown once. Most FlowPrime services take it in the X-Api-Key header; the webhook router takes it as Authorization: Bearer ffk_... (see platform_guide topic=webhooks). Use it for server-to-server calls, or to connect an MCP client that cannot sign in with OAuth.

Treat a key as a password with your own powers: a key with no scopes acts with the full role of the person who minted it (an org admin's key can do everything an org admin can). Keep it on a server and revoke it with auth_revoke_api_key when it is no longer needed. A key created without expiresAt never expires: always pass expiresAt (a future ISO-8601 moment; 90 days is a good default) and mint a new key before it ends. It is not a sign-in for your users. auth_list_api_keys and auth_revoke_api_key manage your own keys.

Scopes narrow a key to what it is for. Pass them comma-separated; an unknown scope is refused at creation (invalid_scope), so a typo never mints a key that fails at first use. Keys created before this rule keep their scopes.

Scope What the key may do
ff:feedback:read Feedback: read boards, tickets and releases
ff:feedback:write Feedback: write tickets, releases and deployment stamps
storage:read, storage:write, storage:delete Storage: read, upload, delete files
router:admin Webhooks: manage the workspace's webhook routes
mcp:connect Connect an AI client to the FlowPrime MCP with this key

A wildcard such as storage:* or ff:feedback:* covers every scope under it. Services not in this list do not take an ffk_ key with a scope; leave scopes empty for a key every service accepts.

Connecting AI assistants

Deleting an app

auth_revoke_oidc_app deactivates an app and keeps it in your list; auth_delete_oidc_app removes it for good, by client id. Both work for apps you created yourself and for AI-connector apps. A delete is refused (client_in_use) while a session signed in through the app has not expired; pass force to delete it anyway and sign those people out. The apps FlowPrime itself manages in your workspace (the dashboard's app, the platform service apps) are never deleted (platform_managed). Before deleting an app you created, make sure no deployment still uses its client id: a backend using client credentials holds no session, so nothing warns you.

Things that trip agents up

When sign-in is refused

The refusal page links here with the reason code as the anchor. The same code is the reason field of a token endpoint error.

no_seat

The person signed in, but holds no seat on this app's surface. The page reads one of three ways:

On a free-tier app a fresh sign-up is not refused: it is sent to verify the e-mail first.

team_on_customer_app

A team member (staff, org_admin or member) opening a customer app is refused with reason no_seat, and the page says "This app is for ...'s customers". When the app has a checkoutUrl, the page offers that checkout instead, so the operator can buy their own product. Cause: staff roles never ride on customer tokens, and staff hold no customer seat by default. Two fixes:

  1. Test with a second e-mail address that signs up or buys like a customer.
  2. Give your own e-mail a seat: buy through the checkout (you become the owner of a new account) or accept an invitation from an account owner. Your team role stays.

If the person is meant to use an admin console, give that console its own platform app instead.

The person exists but is not linked to this workspace any more (it shows as linked: false in auth_get_org_member). Fix: they sign up again with the same e-mail address on your sign-in page, which relinks the account; nothing else is lost.

wrong_surface

The identity cannot enter this app's surface. Two causes:

on_behalf_not_allowed and not_in_account

A machine sent on_behalf_of on its client credentials request. on_behalf_not_allowed: turn actsForAccountMembers on for that app (auth_update_oidc_app). not_in_account: the person named is not a member of the customer account the app is pinned to; the app can act only for that account's members.

org_inactive

The workspace behind this app is no longer active: its FlowPrime plan was cancelled or the workspace is suspended. During the retention window after a cancellation only the workspace admin can still sign in, and only to the FlowPrime dashboard; after it, nobody. Fix: the workspace owner renews the FlowPrime subscription from the dashboard billing page.

Reference

Where to go next