Add work-account or Apple sign-in #
On this page
Prompt:
Let our staff sign in with their work accounts.
Also works:
- "Only people at our company should be able to use the app."
- "Add Sign in with Apple to the sign-in page."
Your AI tool stores the company's client secret or Apple's signing key (step 1), then adds the method (step 2; step 4) and checks it with tzcloud_check_app_sign_in. In the company's app registration you list the callback address it returns and add two optional claims (step 2). For Apple, the Services ID lists that address as its return URL (step 4).
What your AI tool does #
- Reads the
add-sign-inskill (read_context, idskill:add-sign-in) and follows it. - Stores the secret or key by name with
tzcloud_store_secret, as Store a secret describes, so its value never passes through your AI tool. - Sends the
entraorapplemembers with the method, throughtzcloud_configure_app_sign_inor the manifest'srealmmember. - Gives you the callback address the answer returns, for you to list in the company's app registration or Apple's Services ID.
- Calls
tzcloud_check_app_sign_into check the stored credential, the token endpoint's test response, and whether the sign-in page offers the method. It follows each method'sdetailor makes thenextcall. - Asks you for the registration's details, listed under What you need, and for the name to store the client secret or signing key under. It never asks for the secret itself.
What you need #
- For work accounts: an app registration in the company's Microsoft Entra tenant, with its tenant identifier (a GUID), its client identifier, and a client secret. You add a redirect URI and two optional claims to it in step 2.
- For Sign in with Apple: in your Apple developer account, a Services ID, a Sign in with Apple key as its
.p8file, its key identifier, and your team identifier.
Before your AI starts #
For the AI tool: Check the following before starting.
- A connected, signed-in AI tool (Connect your AI assistant).
- The application's identifier from
tzcloud_list_applications, and a manifest that declares the accounts service (Add sign-in to your app). - Whether the realm is invitation-only: the work-account method cannot be used with invitation-only sign-up (Make sign-up invitation-only).
Steps #
1. Store the client secret or the signing key #
Store the work-account client secret, or the Apple key's .p8 file, by name at the application's scope in the realm's environment, as A key that a sign-in method uses describes. Development, once turned on, takes a second call with environment: "development".
tzcloud_configure_app_sign_in then moves the value into the realm vault, where it stays under that name and only the accounts service reads it. You rotate it by name as before. After a change of name, the earlier name stays in the realm vault. No upstream declaration can use the name, and a name an upstream of this application already uses is refused.
2. Add work-account sign-in #
A work account is a person's Microsoft Entra account at one company. Call tzcloud_configure_app_sign_in with entra and with entra in sign_in_methods.
{
"application": "<application id>",
"sign_in_methods": ["entra"],
"entra": {
"tenant": "00000000-0000-4000-8000-000000000001",
"client_id": "00000000-0000-4000-8000-000000000002",
"client_secret_name": "entra-client-secret"
}
}
tenantis the company's tenant identifier, a GUID;client_idis the client identifier of the app registration in that tenant;client_secret_nameis the name step 1 stored the client secret under.
Saving entra stores the work-account details, and the method appears on the sign-in page once sign_in_methods includes entra. The list replaces the current one, so name the other methods beside entra to keep them (Offer other sign-in methods).
In the app registration, add callbacks.entra as a web redirect URI, exactly as returned. tzcloud_read_app_sign_in and tzcloud_configure_app_sign_in return it once the manifest declares accounts, even before Entra is configured. tzcloud_submit_manifest also returns it as realm.entra_callback when the manifest names entra. Both application environments use the platform's callback, https://turnzero.ai/auth/entra/callback, rather than the application's hostname.
In the app registration's Token configuration, add the optional claims email and xms_edov to the ID token. A work-account user's address is the email claim the tenant sends. It is verified only where the token also carries xms_edov as true, meaning the address's domain owner is verified, and unverified otherwise. The address comes marked source: "tenant", and a route that needs a verified address reads verified first.
A verified work address is one account's address. At its first sign-in, a person whose address another sign-in method already holds is asked to link, not given a second account. A work account whose verified address another account already holds can sign in with that address unverified. That happens on a realm without the emailed code, or where the other account holds the address through a work account alone. A code sent to an address that only a work account holds verified asks the person to sign in with that work account to link.
The work-account method cannot be used with invitation-only sign-up, whether the realm's creation or the invited audience makes it so.
Then your AI tool checks the method with tzcloud_check_app_sign_in, passing the application, and environment: "development" for development. Nobody signs in. For each of entra and apple the realm sets, the answer gives three outcomes. credential says whether the stored secret reads, provider gives the token endpoint's test response, and route says whether the sign-in page offers the method.
For Entra, accepted means the client-credentials probe returned invalid_resource for a deliberately nonexistent resource. The mapping treats that refusal as acceptance of the client identifier and secret; no token is issued by that refusal.
That accepted response still awaits a live check with the stored secret. For Apple, accepted means the endpoint returned invalid_grant. The platform infers that this response signals acceptance, but that inference is unverified. It proves neither the client identifier nor the signing key.
If Entra's provider.outcome is unknown with code 90002 or 900023, check the tenant setting. Code 90002 means Entra couldn't find the tenant. A placeholder or a mistyped tenant can cause this. Code 900023 means the tenant identifier is malformed.
Read the tenant with tzcloud_read_app_sign_in. Compare it with the tenant ID in the Entra app registration. You can find the real Tenant ID in the Microsoft Entra admin center under Entra ID > Overview > Properties. If the IDs differ, correct the configured tenant. Change realm.entra and call tzcloud_submit_manifest if the manifest sets it. Use tzcloud_configure_app_sign_in if the manifest leaves realm.entra out. Then run tzcloud_check_app_sign_in again. Keep the current client secret while you check the tenant.
An unknown outcome leaves the client identifier and secret unverified. When it includes an HTTP status, the token endpoint replied. For other unknown outcomes, follow the method's detail and run the check again.
The first real sign-in checks the client credentials, the registration's redirect address and, for work accounts, the ID token's email and xms_edov claims.
A method that needs a step carries a detail naming it, such as storing the secret with tzcloud_store_secret or correcting the identifiers with tzcloud_configure_app_sign_in. Where the secret is stored but not yet in the realm vault and the manifest's realm member names it, next is the tzcloud_submit_manifest call that moves it. One account makes at most ten checks a minute.
3. Allow only one company's staff #
To let only one company's staff reach the application, declare the workforce audience with that tenant and the realm's entra method together. The audience decides who may reach the app, and the realm's entra method, set up with the same tenant, is what signs them in, so declare both.
A workforce audience allows only the entra method of its declared tenant, so its realms offer no other method, and tzcloud_configure_app_sign_in refuses email there. Outside the paths the audience lists in session_free_paths, the platform refuses a request without a session before it reaches your code, and sends a browser to the sign-in page. A submission declaring the audience without the method is still accepted, because tzcloud_configure_app_sign_in can add the method later. Until then no one can sign in, and the response's detail names each realm still missing the method.
The deploy's health check calls the health path from inside the platform, so the gate never refuses it and a deploy needs no listing. List the path in session_free_paths only where something outside the platform probes it, such as an uptime monitor, as The audience kinds says.
With your management credential, use tzcloud_read_status to read the deploy's recorded health check result without an application end-user session; the call sends no fresh probe.
Keep the realm's creation at open, the default. The audience already admits the tenant's staff alone, and invited refuses the work-account method, so tzcloud_configure_app_sign_in refuses invited while that method stands.
{
"manifest_version": 1,
"services": [{ "kind": "accounts" }],
"health": "/health",
"region": "usa",
"egress": [],
"audience": { "kind": "workforce", "tenant": "00000000-0000-4000-8000-000000000001" },
"packages": [],
"realm": {
"sign_in_methods": ["entra"],
"entra": { "tenant": "00000000-0000-4000-8000-000000000001", "client_id": "00000000-0000-4000-8000-000000000002", "client_secret_name": "entra-client-secret" }
}
}
The manifest's realm member sets the method on every realm the application has at each submission, and a client secret not stored yet is accepted there (Configure sign-in and push in the manifest). Sign in from a native app compares public and workforce for a mobile backend.
4. Add Sign in with Apple #
Call tzcloud_configure_app_sign_in with apple and with apple in sign_in_methods:
services_id, the Services ID the web sign-in uses;team_idandkey_id, each ten characters;key_secret_name, the name step 1 stored the signing key under.
The platform reads the key only to sign Apple's client secret. The apple method signs people in on the sign-in page with Apple's own pages. It can be used with invitation-only sign-up, because Apple verifies the address.
In Apple's Services ID, set the return URL to callbacks.apple from tzcloud_read_app_sign_in, exactly as returned, and the domain to that URL's host. Both application environments use the platform's callback, https://turnzero.ai/auth/apple/callback, rather than the application's hostname.
Then your AI tool checks the method with tzcloud_check_app_sign_in, as step 2 describes. A signing key that cannot sign Apple's client secret answers credential unreadable.
A person may hide their address behind Apple's private relay, which the realm accepts as any verified address. For a relay address to receive the platform's mail, register donotreply@turnzero.ai and its domain, turnzero.ai, with Apple's private email relay for your team. A native app can also exchange Apple's own ID token for a session (Sign in from a native app).
Expected result #
tzcloud_configure_app_sign_in returns the realm with its entra or apple settings, never the secret, and callbacks, the two addresses the registrations list. Its detail says the method is set, and that it is offered once sign_in_methods includes it. The sign-in page then shows the new method. tzcloud_check_app_sign_in can answer credential read, provider accepted, and route serving. These outcomes still leave the registered callback and the provider's returned identity to a real sign-in; Apple's client credentials remain unproved by this check.
Someone then signs in with a real work account or Apple account to prove that method. After a work-account sign-in, GET /__account/me returns their address marked "source": "tenant". Under the workforce audience, a visitor without a session is sent to the sign-in page.
Proving a workforce deployment #
After a deploy, prove four things separately: the gate, the signed-in path, the tenant's own sign-in, and your code's tenant check.
Your AI tool signs a test end user in under its own signed-in session, in either environment, with no approval. A token you minted, such as an unattended job's, does the same where you gave it the test_end_users grant (A token for test end users). Without the grant it is refused in each environment (Test on production from a pipeline).
A manifest change to the audience or the tenant leaves a minted token with the test_end_users grant admitted. Revoke that token to end its access.
- Your AI tool proves the gate on your own paths, outside the ones your audience lists in
session_free_paths. There a request without a session never reaches your code. AGETorHEADasking for HTML is sent to the sign-in page, and any other request receives 401authentication_required, whosedetailnames the serving router. Paths under/__account/, and the well-known files the platform serves for native clients, are the platform's own and answer for themselves. - Your AI tool proves the signed-in path. Once the realm's
entramethod names the declared tenant, it creates a test end user and signs it in at the test sign-in page,/__account/signin/test, whichtzcloud_add_test_end_userswithlabelsreturns astest_signin_page. It then requests a route that admits any signed-in user. That route answers 200, andGET /__account/mereturns the test end user's address atsynthetic.turnzero.aiwith nosource. A route that admits only tenant addresses refuses it. - Someone with a work account in the company's tenant, you or a colleague, proves the tenant's own sign-in. They open the application's address in a browser and sign in with their own work account. A route that admits only tenant addresses then answers 200, and
GET /__account/mereturns their address marked"source": "tenant". - Your tests prove offline, over the Account package's double, that a route admitting only tenant addresses admits a tenant user and refuses others (Test with the double).
Refusals #
See the refusals reference for other platform errors.
Where the manifest's realm member sets the credential, tzcloud_submit_manifest or tzcloud_create_environment returns custody_entry_missing, custody_entry_unmovable, and name_bound_to_setting instead. The manifest stays recorded. Your AI tool then stores the value again, stores it under a new name that the manifest names, or removes the binding, and submits the manifest again.
| Refusal | Status | Cause | Remedy |
|---|---|---|---|
custody_entry_missing |
409 | tzcloud_configure_app_sign_in named a client secret or Apple signing key that is not stored at the application's scope in the realm's environment. |
Store it with tzcloud_store_secret for the application and environment, as Store a secret describes, then call tzcloud_configure_app_sign_in again. |
platform_minted_name |
409 | tzcloud_configure_app_sign_in named a credential the platform minted, credential-<application id>, database-<application id>, or issue-tracking-<application id>, as the client secret or the Apple signing key. |
Store the client secret or the key under your own name with tzcloud_store_secret, as Store a secret describes, and name that. |
name_bound_to_upstream |
409 | tzcloud_configure_app_sign_in named, as the client secret or the Apple signing key, a secret that an upstream of this application uses. |
Store the client secret or the key under another name at the application's scope, and name that. |
name_bound_to_push |
409 | tzcloud_configure_app_sign_in named, as the client secret or the Apple signing key, a secret that a push configuration of this application uses as a provider credential. |
Store the client secret or the key under another name at the application's scope, and name that. |
name_bound_to_setting |
409 | tzcloud_configure_app_sign_in named a client secret or Apple signing key that a setting binds: the manifest's settings, the running copy of either environment, or a deploy, promote, or redeploy in flight to one. The detail names the setting and where it is bound. |
Store the client secret or the key under another name at the application's scope, and name that. A running copy keeps its binding until that environment's next deploy or promote of a manifest without it, and an action in flight keeps it until the action ends. |
realm_vault_unregistered |
409 | The platform has no realm vault set up for the application's hosting cell, so the client secret or the Apple signing key has nowhere to move. | Report it to platform staff; nothing on your side fixes it. |
custody_entry_unmovable |
409 | The realm vault already has an entry under the name of the client secret or the Apple signing key, live or soft-deleted, at another version. Nothing moved. | Store the value under a new name with tzcloud_store_secret, as Store a secret describes, and name that. |
invited_realm_refuses_work_account |
409 | tzcloud_configure_app_sign_in combined invitation-only creation, by creation: "invited" or by the invited audience, with the entra method. |
Leave entra out of sign_in_methods. Where the realm's own creation makes it invitation-only, set creation: "open" under a public audience. |
declared_tenant_contradicts_route |
409 | The workforce audience gives a different tenant from the work-account method of one of the application's realms, and the refusal's environment names which. |
Declare that method's tenant, or call tzcloud_configure_app_sign_in for the named environment with the audience's tenant. |
route_set_contradicts_audience |
409 | Under a workforce audience, tzcloud_configure_app_sign_in named a method such as email, or an entra.tenant other than the declared one. |
Name entra alone with the declared tenant, or change the audience and resubmit the manifest. |
manifest_owned_field |
409 | tzcloud_configure_app_sign_in would change entra, apple, or sign_in_methods while the manifest's realm member names it. |
Change the field in the manifest and submit it, or remove it from the realm member first (Configure the realm). |
Related #
- Add sign-in to your app turns sign-in on and tells your backend which user sent a request.
- Store a secret stores the client secret and the signing key by name.
- Manage end users lists every realm setting and which ones the manifest owns.
- Make sign-up invitation-only covers the other audience that limits who may reach the app.
- Sign in from a native app signs in a mobile app's users, and exchanges Apple's own ID token.
- Build a mobile app's backend joins these steps for a mobile backend that signs in one company's staff.
- tzcloud_configure_app_sign_in in the generated reference gives the
entraandapplemembers' exact forms. - tzcloud_check_app_sign_in in the generated reference gives each outcome the check returns.