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."
Choose who can sign in. To add a work sign-in option, follow Add work-account sign-in for Microsoft Entra or Configure your company's OpenID Connect issuer. To limit the app to one company, start with Allow only one company's staff. Check the app’s sign-up settings first. Work-account sign-in is unavailable with invitation-only sign-up.
Your AI assistant 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 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 assistant. - Configures
entra,apple, oroidcthroughtzcloud_configure_app_sign_inor the manifest'srealmmember. - Gives you the callback addresses to register with the work-account provider or in Apple's Services ID. Step 5 explains where to register each OpenID Connect callback.
- Calls
tzcloud_check_app_sign_into check whether the stored credential reads and the sign-in page offers the method. Forentraandapple, it also reads the token endpoint's test response. It follows the method'sdetailor the check'snextcall. - 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 #
Your AI assistant checks these requirements before starting.
- A connected, signed-in AI assistant (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, the OpenID Connect client secret, or the Apple key's .p8 file by name at the application's scope in the realm's environment. A key that a sign-in method uses gives the steps. Development, once turned on, takes a separate 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_read_app_sign_in for the environment you are configuring and read realm.sign_in_methods. Check whether the manifest sets realm.sign_in_methods. Check the provider's own settings in the manifest as well. Change each field the manifest sets there, then submit it. Use tzcloud_configure_app_sign_in for the fields the manifest leaves out, in each environment. If you send a list of methods, include every method people should still be able to use. The example chooses Entra alone in production. To keep other methods, list each one beside entra. For development, pass environment: "development".
{
"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://dev.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.
Only one account can hold a verified work address at a time. 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.
Ask your AI assistant to run tzcloud_check_app_sign_in for the application. Pass environment: "development" when checking development. The response lists the configured methods in Entra, Apple, and OpenID Connect order. credential tells you whether Turn Zero could read the saved secret or key. route tells you whether the sign-in page offers that method. Read detail for an explanation and use next when the response gives a follow-up call. Then try a real sign-in in the same environment.
For oidc, the check calls no provider and provider.outcome is always not_checked. When the credential reads and the page offers the method, that entry's detail asks you to open the sign-in page, choose Continue with SSO, and sign in once. This confirms the provider accepts the registration, the stored secret, and the callback. When the oidc credential reads, the answer gives no next call for it.
For entra and apple, provider reports the token endpoint's test response when the check reaches it. After the check, test a real sign-in with the configured method in the same environment.
Before the first deploy in that environment, open /__account/signin on its application hostname. Entra, Apple and company OpenID Connect sign-in can finish there once the method is configured. The browser may then show a 404 with not_deployed when it returns to your app. Open /__account/me on the same hostname and check that the response names the signed-in user. Deploy a version before testing your app’s own routes.
For Entra, accepted means the client-credentials probe returned invalid_resource for a deliberately nonexistent resource. The platform reads invalid_resource as a sign that Entra accepted the client ID and secret. Entra issues no token in that response.
For Entra, test a real sign-in to check the callback and the user's returned identity. 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 reports code 90002 or 900023, check the tenant ID. The code can appear with provider.outcome set to unknown or refused. 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 and the registration's redirect address. For Entra, it also checks 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 limit access to one company, declare a workforce audience and configure the realm’s matching sign-in method. Choose the form your company uses.
- Microsoft Entra ID. Put the company’s tenant ID in
audience.tenantandrealm.entra.tenant. Listentraas the realm’s only sign-in method. - Your company’s OpenID Connect issuer. Put its HTTPS issuer address in
audience.tenantandrealm.oidc.issuer. Match it exactly, including letter case and any trailing slash. Listoidcas the realm’s only sign-in method and configure it as step 5 describes. Use your company’s own issuer. Anyone who can sign in through it for this app can reach the app.
A workforce realm serves only the sign-in method that matches the declared tenant ID or issuer. It offers no passwordless sign-in. 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. You can submit the audience before you configure the matching method with tzcloud_configure_app_sign_in. Until the matching method is set up, no one can sign in, and the submission’s detail names each realm still missing it.
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 workforce audience already limits who can sign in. While a work-account method is enabled, tzcloud_configure_app_sign_in refuses invited creation.
{
"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 #
Use the same field rules for Apple. Give the apple settings below and include apple in the complete method list.
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://dev.turnzero.ai/auth/apple/callback, rather than the application's hostname.
Then your AI assistant 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 each sender address or its exact domain with Apple's private email relay. Use no-reply@mail.ai.host (mail.ai.host) for the production estate and no-reply@mail.dev.ai.host (mail.dev.ai.host) for the development estate. To receive backup mail too, keep donotreply@turnzero.ai or turnzero.ai registered. A native app can also exchange Apple's own ID token for a session (Sign in from a native app).
5. Configure a company's own OpenID Connect issuer #
Use the company's own OpenID Connect issuer. Ask the provider administrator for its exact HTTPS issuer and the application's client ID. The issuer has no user information, query, or fragment. It must match the discovery document's issuer exactly, including a trailing slash. For the existing Entra route, use entra.
Register a confidential web client with a client secret for the authorization code flow. The registration must accept the flow without PKCE and allow the openid, email and profile scopes. The token endpoint must return an ID token. Turn Zero sends the secret in the request body (client_secret_post) when the discovery document lists that method. Otherwise, it uses HTTP Basic authentication (client_secret_basic). If the provider changes which method it accepts, configure the route again.
From the manifest. Include the accounts kind in services. In realm, give oidc with issuer, client_id, and client_secret_name. List oidc in realm.sign_in_methods to offer it. For a workforce audience, list oidc alone and give the same issuer address in audience.tenant. For other audiences that allow oidc, include any other methods you want to keep. tzcloud_submit_manifest records the settings on each realm the application has. tzcloud_create_environment records them on the development realm it adds.
The submission's realm.oidc_callbacks gives each existing environment's callbacks.oidc. Register every address exactly as returned in the provider registration for the manifest's one client_id.
The sign-in settings take effect when tzcloud_submit_manifest or tzcloud_configure_app_sign_in succeeds. No deploy, promote or restart is needed for that change. Sign-in also needs the provider registration and the client secret in the realm vault.
If your provider uses a separate client for each environment, leave the oidc object out of realm. Use tzcloud_configure_app_sign_in for each environment with its own client.
You can submit before you store the client secret. The answer's detail names each missing secret, and next gives the tzcloud_store_secret call. Store the secret and submit the manifest again to move it into the realm vault. On a deploy, a promote, or tzcloud_check_deploy, look for provider: "oidc" in provider_credentials_missing. An empty or absent list can mean the records could not be read. Run tzcloud_check_app_sign_in and test a real sign-in in the same environment.
For one environment. First store the provider's client secret with tzcloud_store_secret for the application and environment you are configuring. In tzcloud_configure_app_sign_in, send an oidc object with issuer, client_id, and client_secret_name. Supply the stored name for client_secret_name and keep the value in secret storage.
{
"application": "<application>",
"sign_in_methods": ["oidc"],
"oidc": {
"issuer": "https://login.example.com",
"client_id": "<client-id>",
"client_secret_name": "work-account-client-secret"
}
}
The list replaces the current list. Use one work-account route per realm, either oidc or entra. Invitation-only realms refuse both. For a workforce realm whose audience.tenant is an issuer address, list only oidc and match that address exactly. Where the workforce audience declares a Microsoft Entra tenant ID, list only entra. For other audiences that allow this route, include the other methods you want to keep.
A submission reads the provider's discovery document if the issuer differs from the one the realm stores. tzcloud_configure_app_sign_in reads it on every call that includes oidc. When the manifest sets oidc, a call repeating all three values passes and refreshes any moved endpoint. A call that changes issuer, client_id, or client_secret_name is refused with manifest_owned_field. Change those fields in the manifest and submit it again.
Register the realm's own redirect address from callbacks.oidc in the provider's client registration. The address is specific to the application and environment. If the application has development and production, configure each realm and register its own address. Pass environment: "development" in the development call. The example above configures production. Use tzcloud_read_app_sign_in for that environment to read the saved settings and callback again.
With oidc in sign_in_methods, the realm's page offers Continue with SSO. The person signs in at the company's provider and returns signed in to the app. Test each environment on its own sign-in page using the callback for that realm. If tzcloud_check_app_sign_in reports the oidc credential as not_moved and the recorded manifest names that secret, follow the answer's next to submit the recorded manifest.
The platform records the provider’s email address as unverified when it can store that address. It leaves out addresses longer than 254 characters or containing text it cannot store. Sign-in can still succeed without an email address. For a user with only work-account identities, a recorded address appears as verified: false with source: "tenant".
Sign-in identifies the person by the issuer and the provider's subject together. It never joins a user by address. If a person already has an emailed-code account, a first SSO sign-in creates a separate user where the realm allows sign-up. Changing the issuer or switching between entra and oidc gives people new users when they sign in again. Their earlier users stay until the owner removes them.
When the app needs fresh authentication, the provider asks the person for their credentials again. The platform refuses reauthentication_not_fresh if the provider's token gives no auth_time or reports a sign-in outside the freshness window. Use an emailed code or passkey where the realm offers it and the user can use it for that account.
A refused return from the provider can name issuer_mismatch, audience_mismatch, nonce_mismatch, token_exchange_failed, client_secret_unreadable, subject_missing, or sign_in_failed. sign_in_failed can mean the platform could not verify the provider's token. It accepts RS256 and ES256 signatures. The page names the refusal and says “The provider sign-in could not be verified. Nothing was signed in and nothing was created.” Compare the issuer, client ID, and stored secret with the provider's registration. Register the exact callbacks.oidc address. If the provider moved an endpoint, call tzcloud_configure_app_sign_in again to refresh the addresses.
Expected result #
For entra and apple, tzcloud_configure_app_sign_in returns their realm settings, the registration's callback address under callbacks, and no secret value. Its detail names the configured method and adds "with sign-in disabled" if sign_in_methods leaves it out. Once sign_in_methods includes the new method, open that environment’s sign-in page and check that it offers the 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.
For oidc, tzcloud_configure_app_sign_in returns the issuer, client ID, stored secret name, and the realm's own callback. A manifest submission returns the callbacks in realm.oidc_callbacks. Register each address, then check the method and sign in once with Continue with SSO.
Someone then signs in with a real work account or Apple account to check that method. A work-account sign-in can succeed even if GET /__account/me has no usable email address to return. On a returned address, "source": "tenant" means it came from the work account. Check verified separately to see whether the tenant verified the address. 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 assistant 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 token you minted with the test_end_users grant still works after you change the audience or tenant in the manifest. Revoke that token to end its access.
- Your AI assistant 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. The platform handles/__account/paths and the well-known files it serves for native clients directly. - Your AI assistant proves the signed-in path. Once the realm serves the work-account method that matches
audience.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. - Ask someone with a work account at the declared Entra tenant or OpenID Connect issuer to check the company’s sign-in. They open the application’s address in a browser and choose the configured method. For OpenID Connect, they choose Continue with SSO. Record whether sign-in succeeds. If you also test a route that admits only tenant addresses, check separately whether
GET /__account/mereturns an address with"source": "tenant"and whether itsverifiedfield meets the route’s rule. Check that the route answers 200 for an account that meets that rule. - 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.
A manifest submission reports the named OpenID Connect validation rules as manifest_invalid. Each entry in violations gives the rule at its field's path, such as /realm/oidc/issuer: oidc_shared_issuer_refused.
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 assistant 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 included entra or oidc on an invitation-only realm. The realm's own creation setting or its declared audience requires invitations. |
To keep invitation-only sign-up, leave both work-account methods out and keep a method the realm accepts. If you own the app and intend to open creation, choose an audience and creation policy that permit it. The manifest's invited audience keeps invitation-only admission. |
declared_audience_contradicts_route |
409 | A manifest sets the invited audience and leaves a realm's existing sign-in methods in place. That realm lists entra or oidc, and the detail names which one. |
To use the invited audience, remove the named work-account method from that realm before submitting the manifest again. |
declared_tenant_contradicts_route |
409 | The manifest leaves both work-account configurations out of realm, and a realm’s existing work-account configuration disagrees with the declared workforce tenant ID or issuer. The refusal’s environment names the realm. |
Submit the new audience with matching realm.entra or realm.oidc in the same manifest. To keep the configured route, declare its tenant ID or issuer. Use tzcloud_configure_app_sign_in first only if the realm allows work-account sign-in and the recorded manifest does not pin a different workforce tenant ID or issuer. |
route_set_contradicts_audience |
409 | On a workforce realm, tzcloud_configure_app_sign_in named a disallowed method or a work-account configuration that does not match the declared tenant ID or issuer. |
List only entra when audience.tenant is an Entra tenant ID and only oidc when it is an issuer address. Match the tenant ID without regard to letter case, or match the issuer address exactly, including a trailing slash. |
work_account_routes_conflict |
409 | The realm's sign-in methods include both entra and oidc. One work-account route can be enabled for a realm. |
Choose the work-account route to enable and submit the sign-in methods with that one route. |
oidc_shared_issuer_refused |
400 | The oidc configuration uses a shared issuer the platform recognizes. |
Use your company's own OpenID Connect issuer. Use entra for the existing Entra route. |
oidc_address_not_admitted |
400 | The issuer or an endpoint in its discovery document fails the provider address checks. The configuration is unchanged. | Use your company's admitted HTTPS issuer and endpoints. Ask the provider administrator to correct any endpoint in the discovery document, then configure the realm again. |
oidc_discovery_unavailable |
502 | The service could not read a usable discovery document from the issuer. The configuration is unchanged. | Check the issuer and ask the provider administrator to make a usable discovery document available at that issuer. Configure the realm again after the document is available. |
oidc_discovery_issuer_mismatch |
409 | The discovery document identifies an issuer different from the one in the request. Issuer comparison is exact. | Confirm the issuer with the provider administrator. Use the provider's exact issuer address and have the discovery document identify that same issuer. |
manifest_owned_field |
409 | tzcloud_configure_app_sign_in would change entra, oidc, 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 exact configuration for
entra,apple, andoidc. - tzcloud_check_app_sign_in in the generated reference gives each outcome the check returns.