M5-S1 — Identity and tokens inside
Section titled “M5-S1 — Identity and tokens inside”| Module | M5 — Identity, access and security |
| After this session you can | Explain how a person, an application user and an OAuth client become an identity a service trusts, and choose and diagnose credentials from that understanding. |
| Time | 64 min with a facilitator · about 64 min on your own |
| Before you start | M2-S1 (the life of a request). Larkspur Lab, Rami Aziz signed in, the workbench API window and the lab’s mail catcher open. |
| Go deeper | Authentication and OAuth · Choosing a credential · Tenancy and identity · Identity server |
◆ Orientation (1 min) — Every “Executed by” is a trusted identity
Section titled “◆ Orientation (1 min) — Every “Executed by” is a trusted identity”In M4 you read Executed by, owners and executors in the stored records. Each of them is an identity that some service accepted. In ACE M5-S1 and ACE M5-S2 you chose credentials as an integrator: an API token for a program, the authorization-code flow for a person, an anonymous token for a visitor. In ACDE M4-S1 you ran the identity server. This session joins those views from the inside: where each identity is established, where it is checked, and why a service can believe it. M5-S2 then takes the identity and decides what it may do.
▤ Concept (9 min) — Established, checked, trusted
Section titled “▤ Concept (9 min) — Established, checked, trusted”Three places, three jobs
Section titled “Three places, three jobs”flowchart LR C["A caller with a credential"] --> G["Gateway: checks the credential<br/>(introspect or validate, cached)"] I["Identity service:<br/>issues and validates"] -.->|"answers the check"| G G -->|"identity of the caller,<br/>space from the host,<br/>proof it came through the gateway"| S["Service: trusts the identity<br/>only with that proof"] S --> P["Permission engine (M5-S2)"]
What to notice: no service behind the gateway ever sees your token. It sees an identity the gateway vouches for, and the vouching is what it checks.
Established by the identity service, a standard OpenID Connect provider. It runs the sign-in pages, issues tokens to people and programs, and keeps API tokens. Checked by the gateway, on every request: a bearer token is sent to the identity service for introspection (is it active, for whom?), an API token is sent for validation. Trusted by each service behind the gateway, which accepts the caller’s identity only from a request that carries the proof that it came through the gateway: a shared key that only the gateway and the services hold. You operated that key in ACDE M3-S2; here you see why it matters. A service reached by any other path, for example a port exposed past the gateway, has no reason to believe anything about the caller, which is why the deployment never exposes services directly. The same design gives the space: the gateway resolves it from the request’s host and overwrites anything the client sent.
People: the signed-in session
Section titled “People: the signed-in session”A person signs in on the identity service’s pages: password and account policy, a second factor if required, or an external provider for single sign-on. The result is a session (up to 14 days) and, for the web app, tokens issued through the authorization-code flow with PKCE: an ID token (a signed JSON document saying who signed in, for the app itself), an access token (one hour, presented to the API) and a refresh token (14 days, rotated, renewable for at most a year).
Since 1.8 the access token carries the session id, so the platform can tie a sensitive action to
one session: the re-verification you met in M4-S3 binds its proof to it. It also carries the
tenant’s login host as a signed claim, so the tenant is resolved from the token, not from a
header the client controls. The gateway does not read access tokens itself: it introspects them and
caches the answer for at most five minutes and never past the token’s expiry. An inactive or
expired access token is refused with 401 AUTHENTICATION_ERROR.
Programs without a person: application users and API tokens
Section titled “Programs without a person: application users and API tokens”An API token authenticates as an application user: a user record whose type is application user. The token has no scopes of its own; whatever that user may do, the token may do, and nothing more. Inside, the design is deliberate:
| Fact | Consequence for you |
|---|---|
| The secret is 64 random hexadecimal characters; only a slow, salted hash (argon2id) is stored | Nobody, administrators included, can read a token back. A lost token is replaced, never recovered |
| The plain token is produced once, when the user is created, and sent to the person who created it | Create application users from an account whose mail you read |
| Since 1.10 the token follows the user record by reconcile: any change re-reads the record and makes the token match | Deactivate the user to stop the token; archive it to delete the token |
Expiry is a date (yyyy-MM-dd) and fails closed; an unreadable date counts as expired | A wrongly formatted expiry silently stops an integration |
| Regenerate Token issues a new secret and keeps the old one valid for 24 hours by default | Roll the integration over within the overlap window |
| The gateway caches a successful validation for five minutes | A deactivated token can keep working for up to five minutes |
The last row is the one people forget. Revocation is not instant: it takes effect when the cached answer expires. Plan an incident runbook around five minutes, not zero.
A refused API token. The identity service answers a deactivated or unknown API token with a 400,
which the gateway passes on as 400 INVALID_APP_TOKEN_API_ERROR. The integrator documentation lists
401 INVALID_APP_TOKEN instead; the product answers 400. The lesson: branch on the code, not on the
number, and never retry a refused credential unchanged.
Programs as themselves: OAuth clients
Section titled “Programs as themselves: OAuth clients”An OAuth client with a secret can use the client-credentials flow and act as itself, with no user behind it; its tokens last ten minutes by default. Clients are not created in the portal: on a single-tenant release they are seeded from the identity service’s configuration at start-up, and since 1.10, in a multi-tenant deployment, every tenant has its own provider: its own issuer address, signing keys, clients and sessions. Two consequences for an integrator: validate a token against the issuer of the tenant you call, never a shared one; and expect the tenant’s signing key to rotate, with the previous key published for 24 hours so caches can catch up.
Credential problem or access problem?
Section titled “Credential problem or access problem?”| Answer | Where it came from | What it means | What to do |
|---|---|---|---|
401 AUTHENTICATION_ERROR | Gateway, introspection | The bearer token is not active or expired | Refresh once, then sign in again |
| 400 or 401 on an API token | Gateway, validation | The token is unknown, deactivated, expired or archived | Stop; issue or regenerate the token |
403 SPACE_FORBIDDEN | Gateway | The identity is fine but not a member of the space | Add the member, or call the right host |
403 INVALID_ACCESS or a permission code | Gateway or service | The identity is fine; the access decision said no | M5-S2: the permission engine |
503 TENANT_IN_MAINTENANCE | Identity service | The tenant is being restored or moved | Wait for Retry-After and retry |
The rule of thumb: a 401 (or the API-token 400) is about who you are; a 403 is about what you may do. Fixing a 403 by issuing a new token changes nothing.
▶ Guided demo (7 min) — The tenant’s identity, from the outside
Section titled “▶ Guided demo (7 min) — The tenant’s identity, from the outside”Starting state. Larkspur Lab; the API window.
- Ask the tenant where it signs people in:
curl -s "$BASE/api/identity/v1/tenant-config" | jq. The answer names the authority (the identity service’s address for this tenant). - Read its discovery document:
curl -s "<authority>/.well-known/openid-configuration" | jq '{issuer, token_endpoint, introspection_endpoint, jwks_uri, grant_types_supported}'. Theissueris the tenant’s own; the grant types include authorization code, refresh token and client credentials. - Read its public keys:
curl -s "<authority>/jwks" | jq '.keys | map({kid, alg})'. Each key has an id; after a rotation the previous one stays listed for a day. - Call the API with no credential at all on an entity read:
curl -s -o /dev/null -w '%{http_code}\n' "$BASE/api/v2/entities/suppliers/entries". The gateway refuses it before any service sees it.
Screenshot pending The discovery document of the Larkspur tenant, with its issuer, token, introspection and jwks endpoints What to notice: the issuer is the tenant’s, not the platform’s; a token from another tenant’s issuer fails validation here.
⛏ Lab (38 min) — Three credentials, three failures
Section titled “⛏ Lab (38 min) — Three credentials, three failures”Goal. Create an application user, watch its token work, be refused for access, keep working after deactivation for the cache window and then fail; and refuse a forged bearer token. For each failure, write down the status, the code and whether it is a credential or an access problem.
Before you start. Rami Aziz signed in to Larkspur Lab as system administrator; the mail catcher open (the lab sends its mail there); a notes table with columns: call, expected, status, code, kind.
Create the credential
- In Administration › Organization › Users, add an application user (User type
Application) Larkspur Audit Reader, email
audit.reader@example.com, no expiry. Save. - Open the mail catcher. The token arrives in a message to Rami Aziz, not to the application user.
Copy it into
export AUDIT="<the token>". - Give Larkspur Audit Reader the system level Restricted, membership of the Larkspur space,
and access to the seeded view Supplier Directory (API) in that view’s access settings, as you did
in ACE M5-S1. Set
export SUPV="<the view's id>".
Use it
- Read suppliers through the view:
curl -s -G "$BASE/api/v1/v/$SUPV/v3/entities/suppliers/entries" -H "x-app-token: $AUDIT" --data-urlencode 'filterCriteria={"limit":3}' | jq '.entries | length'. Three records (av3read answers{entries, tags}, without the{success, result}envelope). - Read one known purchase order directly, which nothing grants it:
curl -s -o po.json -w '%{http_code}\n' "$BASE/api/v2/entities/purchase_orders/entries/<PO-5002 id>" -H "x-app-token: $AUDIT", thenjq '.error.code' po.json. A 403: the identity was accepted, the access was not.
Revoke it
- Deactivate Larkspur Audit Reader in Administration › Organization › Users. Note the time.
- Repeat step 4 at once. It still works: the gateway’s cached validation answers.
- Repeat step 4 every minute. Note the first minute at which it is refused, then save the answer:
curl -s -o rev.json -w '%{http_code}\n' -G "$BASE/api/v1/v/$SUPV/v3/entities/suppliers/entries" -H "x-app-token: $AUDIT"andjq '.error.code' rev.json. - Compare your status and code with the two documented answers in the concept, and record which one your release gives.
Screenshot pending The API window with three answers for the same read: 200 before deactivation, 200 one minute after, then the refusal with its status and code What to notice: the refusal arrives minutes after the deactivation, not at once; the gap is the gateway’s cached validation.
Regenerate it
- Reactivate the user and wait until step 4 works again.
- Use Regenerate Token on the user. The new token arrives in the mail catcher; set
export AUDIT2="<new token>". - Call step 4 with
$AUDIT2: it works. Call it with the old$AUDIT: it also works, inside the 24-hour overlap window.
Forge a bearer token
- Call step 4 with
-H "Authorization: Bearer not-a-real-token"and no API token. Record the status and code: 401AUTHENTICATION_ERROR. - In the logs window, search the gateway’s log for the trace id in that answer’s
error.traceId. The refusal happened at the gateway; no service logged the request. - Clean up. Archive Larkspur Audit Reader. After five minutes, both tokens are refused.
- Fill in the kind column: credential or access, for each refusal.
- Read Monitoring › Audit Logs for the regeneration: it records who regenerated the token, never the token itself.
Check.
- The token arrived to the creating administrator, not to the application user.
- Purchase orders were refused with a 403 and an access code.
- After deactivation the token kept working, then was refused within about five minutes.
- You recorded the release’s actual status and code for a revoked API token.
- During the overlap window both the old and the new token worked.
- The forged bearer token was refused with 401 at the gateway.
Pass condition. Your table has five refusals or delayed refusals, each with its status, code and kind, and the revocation delay you measured.
If something goes wrong
| What you see | What to do |
|---|---|
| No mail with the token | The token goes to the account that created the user. Check the mail catcher for Rami Aziz’s address. |
Step 4 answers 403 SPACE_FORBIDDEN | The application user is not a member of the Larkspur space. Add it. |
| Step 4 answers 403 | The view’s access settings do not include Larkspur Audit Reader, or the view is not opened in this space. |
| The token stops at once after deactivation | Your gateway’s cache was cold or configured shorter; note the value you saw. |
| The old token fails after regeneration | The overlap window is configured to zero on this release; note it. |
Model answer
The token is minted when the application user is created and mailed once to the creator; only its
hash is stored. Through the view built for it, it reads suppliers; a purchase order is outside
everything it was given, so the gateway accepted the identity and the access check refused it with a 403: an
access problem, which a new token would not fix. Deactivating the user made the identity service stop
validating the token, but the gateway kept answering from its five-minute cache, so the refusal arrived
only when the cached entry expired: a credential problem, answered with the status your release
returns for a bad API token. Regeneration kept the previous hash valid for the overlap window. The forged
bearer token failed introspection at the gateway with 401 AUTHENTICATION_ERROR, so no service ever
saw it.
◇ Worked scenario (2 min) — The leaver’s integration
Section titled “◇ Worked scenario (2 min) — The leaver’s integration”Leila Amari’s office reports that a contractor who left on Monday wrote a reporting script that reads supplier data with an API token. On Wednesday morning the script still runs from an unknown machine. Decide at each step before you read on.
Step 1. Whose identity? The script’s token belongs to the application user Supplier Report (contractor), not to the contractor’s own account. Offboarding deactivated the contractor’s person account on Monday, which ended their sessions, but the application user was never part of the offboarding checklist. The token is still valid because its user is active.
Step 2. Stop it, and know when it stops. You deactivate Supplier Report (contractor) at 09:10. Given the gateway’s cache, you tell the security officer the script will be refused by 09:15 at the latest, and you watch the gateway’s log for its refusals to confirm. Archiving the user next deletes the token for good.
Step 3. What did it see? The token could do whatever its user could. Its grants show View on Supplier Management, including the sensitive Bank Account field, because someone granted that field to the user to “make the report complete”. You list the field’s grants for the incident report and remove the one held by the application user.
Step 4. Close the gap. You add three rules to the program’s standard: every application user has an owner recorded in its description and an expiry date; offboarding a person includes every application user they own; and no application user holds a sensitive-field grant without a recorded decision. You add a monthly review of application users by last use.
The lesson: an API token is exactly as powerful, and exactly as long-lived, as its application user. Govern the user, and remember the five minutes.
✓ Practice (6 min) — Check your understanding
Section titled “✓ Practice (6 min) — Check your understanding”An integration’s API token was lost. The administrator asks you to read it back from the platform so the integration can be reconfigured. What do you answer?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
A partner’s program validates the access tokens it receives against the signing keys it downloaded from Larkspur’s identity service last month. Since this morning every validation fails. What is the most likely cause?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
An application user’s expiry date was entered through the API as 2027-01-31T00:00:00Z. What
happens to its token?
Check your answer
The correct answer is C. Open the explanation under each option to see why.
A script receives 403 with the code SPACE_FORBIDDEN. A colleague proposes issuing a new API token.
What do you say?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
At 14:00 you deactivate an application user whose token an attacker is using. At 14:03 the attacker’s calls still succeed. Is something broken?
Check your answer
The correct answer is A. Open the explanation under each option to see why.
↺ Recap (1 min) — Who the platform thinks you are
Section titled “↺ Recap (1 min) — Who the platform thinks you are”You can now say where each kind of caller’s identity is established, checked and trusted; explain an API token from its hash to its revocation window; and tell a credential refusal from an access refusal by its status and code. Next, M5-S2: the permission engine, which takes the identity the gateway vouched for and decides, grant by grant, what it may read and change.