Appearance
End-user authentication
Every TerraScale project has its own sign-in for the people who use your application: an OpenID Connect issuer, hosted sign-in pages and a user directory that belong to that project alone. Your application signs users in with the standard authorization code flow; you manage the users in the dashboard.
| Item | Value |
|---|---|
| Issuer | https://auth.terrascale.tech/<project ID> |
| Discovery | https://auth.terrascale.tech/<project ID>/.well-known/openid-configuration |
| Hosted sign-in | https://auth.terrascale.tech/ui/<project ID>/sign-in |
| Flow | Authorization code with PKCE (S256), refresh tokens with offline_access |
| Scopes | openid, email, profile, offline_access |
End users of one project are separate from every other project and from TerraScale accounts: the same email address in two projects is two unrelated accounts.
Use your project's discovery document for app sign-in. It advertises only authorization_code and refresh_token grants and the four scopes above. It omits device authorization endpoint metadata. Device authorization, client credentials, token exchange and the GitHub Actions workload grant are platform capabilities, described by the platform discovery document at https://auth.terrascale.tech/terrascale/.well-known/openid-configuration.
Set up sign-in in the dashboard
Open Authentication for your project.
- OAuth applications: register your application with a name, its type and its redirect URIs, one per line. Use public for browser, mobile and desktop apps (no secret) and confidential for server-side apps. Creating a client through the API (
POST /v1/{project}/clients) needs the project admin role, your TerraScale sign-in token and a freshcreate_oauth_clientstep-up proof, like updating and rotating below (see sensitive actions). A confidential application's client secret is shown once, right after you create it; store it in your server's secret store. Register 1–10 absolute redirect URIs usinghttps, orhttponlocalhostand loopback addresses, without fragments or userinfo (an embedded username or password). Registration rejects invalid URIs with400 invalid_request; when the project's redirect allowlist is nonempty, each URI must also exactly match an entry there. - Sign-in methods: choose email codes, passwords, or both, and whether people can create their own accounts. At least one of email codes and passwords stays on. A method you turn off disappears from the hosted pages.
- Branding: set the name, an
httpslogo URL and a#rrggbbtheme color. They style the hosted pages and the verification, sign-in and password-reset emails; without a name, both show your project's name. Optionally setemail_messageinbrandingthroughPUT /v1/{project}/settings: up to 500 plain-text characters, newlines allowed, added to those emails. A sentbrandingreplaces the previous one, so send every branding field each time or omitted fields are cleared. HTML and placeholders such asappear as literal text. - Configuration:
redirect_urlsadds a project allowlist of at most 100 exact absolute URLs, without fragments or userinfo (https, or loopbackhttp). A nonempty list further restricts each client's registered redirects; an empty list never permits unregistered redirects.session_lifetime_secondsis an absolute lifetime from original sign-in: 300–2592000 seconds (5 minutes–30 days), default 1209600 (14 days).
Hosted-page Branding also supports title_size (20–40 px), default_theme (light, dark, system), background_color and text_color (#rrggbb), and up to five HTTPS footer_links with label (1–24 characters) and url. Null appearance fields restore defaults; an empty footer list removes project links. Pages read current branding on each request.
Read settings with GET /v1/{project}/settings; update them with PUT at the same path using your TerraScale sign-in token and project admin role. Each supplied configuration or branding object replaces that object; omitted objects stay unchanged. Reducing session policy applies at the next session or grant check. Once a shortened browser expiry is observed it is persisted, and an OAuth sign-in observed past policy expiry is revoked; increasing policy cannot revive it. Issued access tokens retain their short expiry.
Change redirect URIs
When you move a domain or add a callback path, update the registered client instead of creating a new one: the client_id, type and secret stay the same. PUT /v1/{project}/clients/{client_id} replaces the name and the whole redirect list with the same rules as registration (1–10 absolute URIs, https or loopback http, no fragments or userinfo, each exactly matching the project's allowlist when it is nonempty). The change needs the project admin role, your TerraScale sign-in token and a fresh update_oauth_client step-up proof (see sensitive actions); the response is the updated client, without any secret.
sh
curl -sS --fail-with-body -X PUT "https://auth.terrascale.tech/v1/$PROJECT/clients/$CLIENT_ID" \
-H "Authorization: Bearer $TERRASCALE_SIGN_IN_TOKEN" \
-H "X-TerraScale-Step-Up-Proof: $UPDATE_PROOF" \
-H "Content-Type: application/json" \
-d '{"name":"Web app","redirect_uris":["https://app.example.test/callback"]}'Rotate the client secret
Rotating issues a new client secret for a confidential client and answers it exactly once in the response; only a hash is kept, so store it immediately and never log it. The previous secret keeps working for grace_seconds (0 to 86400, default 3600) so you can deploy the new secret without downtime; after the grace it is refused, and previous_secret_expires_at in the response says when. Rotating again inside the grace replaces the previous secret, so only one old secret is ever valid. Rotation needs the project admin role and a fresh rotate_oauth_client step-up proof; public clients have no secret and cannot rotate.
sh
curl -sS --fail-with-body -X POST "https://auth.terrascale.tech/v1/$PROJECT/clients/$CLIENT_ID/secret/rotate" \
-H "Authorization: Bearer $TERRASCALE_SIGN_IN_TOKEN" \
-H "X-TerraScale-Step-Up-Proof: $ROTATE_PROOF" \
-H "Content-Type: application/json" \
-d '{"grace_seconds":3600}'Social sign-in
Open Authentication for your project, then Social sign-in. You can connect four providers: Google, GitHub, Apple, and generic OpenID Connect, which works with any OIDC provider by its https issuer, such as Auth0, Keycloak or another TerraScale project.
Create an OAuth client at the provider
Create the OAuth client yourself, with your own account at the provider. Then register the callback URL that the dashboard shows for that provider:
text
https://auth.terrascale.tech/ui/<project ID>/social/<provider>/callbackHere <provider> is google, github, apple or oidc.
- Google: Google Cloud console > APIs & Services > Credentials. Create an OAuth client ID of type Web application.
- GitHub: Settings > Developer settings > OAuth Apps.
- Apple: Apple Developer > Certificates, Identifiers & Profiles. Create a Services ID with Sign in with Apple enabled, and a key with Sign in with Apple enabled.
Enter the credentials
Paste the client ID and client secret into the provider's form. Apple takes different fields: the Services ID as the client ID, your Team ID, your Key ID, and the .p8 private key file in place of a secret.
Secrets are stored encrypted and are never shown again. When you edit a provider, leave the secret empty to keep the stored one.
What end users see
The hosted sign-in and sign-up pages show a Continue with Google, Continue with GitHub, Continue with Apple or Continue with single sign-on button for each provider you configure. If your application already uses the hosted pages, it needs no code change: the same authorization code flow described above handles social sign-in.
An end user signs in only with a provider that confirms a verified email address:
- Sign-in matches a previously linked provider identity (provider, issuer, client ID and subject); accounts are never linked by email.
- A new identity whose email is new to the project creates an account only if the project allows sign-up. An identity whose email already belongs to an email/password account is refused; that user signs in with their password once, then connects the provider from the security page.
- A signed-in user connects a configured provider, or disconnects one, on the account security page. Connecting needs a sign-in from the last 10 minutes, and a provider account already connected to any account in the project is refused.
- Disabled users cannot sign in this way. Users with MFA continue to the hosted second-factor step.
Manage providers through the API
These calls need the project admin role and your TerraScale sign-in token.
| Method and path | Purpose |
|---|---|
PUT /v1/{project}/providers/{provider} | Configure a provider. Body: client_id, client_secret, issuer (oidc only), team_id and key_id (apple only). |
DELETE /v1/{project}/providers/{provider} | Remove a provider. |
GET /v1/{project}/settings | List the providers with configured and callback_url. |
Sign users in
Use a maintained OpenID Connect library with authorization-code and PKCE support, configured with your exact project issuer and discovery URL. Use its authorization and callback validation APIs:
- Create a short-lived, browser-bound, single-use authorization attempt containing cryptographically random
state,nonceand PKCE verifier. Keep the verifier private and bind the attempt to the initiating browser session, expected issuer, client ID and redirect URI. - Send the browser to the discovered authorization endpoint with
response_type=code,client_id, an exactly registeredredirect_uri, the scopes,state,nonce, and the verifier'sS256code_challengewithcode_challenge_method=S256. Requestoffline_accessif you need refresh tokens. Addui_locales(for examplept-BR) to choose the hosted sign-in pages' language: the first supported value wins (en,pt-BR), then the browser'sAccept-Language, then English. - At the callback, require the initiating browser's attempt and an exact
statematch before accepting either success or error. Reject missing, expired, mismatched or reused attempts and duplicate response parameters. Consume the attempt atomically once; then handle an OAuth error or redeemcodewith that attempt's originalredirect_uriandcode_verifier. Public clients sendclient_id; confidential clients authenticate with their server-held secret. The token endpoint validates PKCE; never retry a consumed code automatically. - Before creating your app session, have the library validate the ID token's signature using the trusted issuer's discovered JWKS and permitted algorithm, exact
iss,audfor your client (andazpwhere required), time claims (exp,iat,nbfif present) and exact attemptnonce. Decoding a JWT is not validation. If you call the discovered userinfo endpoint with the access token, require itssubto equal the validated ID token'ssubbefore using its claims.
The access token is a JWT with your project's issuer as iss, your client ID as aud and the user's ID as sub. Your API must verify its signature, issuer, audience and time validity; an ID token is for the client sign-in, not API authorization. /oauth/userinfo returns sub, and email with the email scope. Access tokens last 5 minutes.
In Python, verify it with PyJWT (install pyjwt[crypto], which brings the cryptography package ES256 needs). PyJWKClient fetches and caches the project issuer's keys; every published key is ES256, and the JWKS URL is also the discovery document's jwks_uri:
python
import jwt
issuer = f"https://auth.terrascale.tech/{project_id}"
jwks = jwt.PyJWKClient(f"{issuer}/.well-known/jwks.json")
key = jwks.get_signing_key_from_jwt(access_token)
claims = jwt.decode(access_token, key.key, algorithms=["ES256"],
audience=client_id, issuer=issuer)jwt.decode raises jwt.InvalidTokenError (such as InvalidSignatureError, ExpiredSignatureError, InvalidAudienceError or InvalidIssuerError) when any check fails; treat every subtype as one rejection.
Refresh tokens rotate on every use. The initial project refresh token expires at original sign-in (auth_time) + configured project session lifetime (5 minutes–30 days, default 14 days). Rotation never extends the observed expiry; a policy reduction can shorten it further. Store each successor securely and stop using its predecessor. Keep tokens and client secrets out of URLs, logs and browser persistent storage. On sign-out, clear your app session, use /oauth/logout for hosted sign-out and /oauth/revoke for token revocation; these are separate from clearing local state.
A project issuer serves only the authorization code and refresh token grants. Project clients also support RFC 7009 token revocation at the discovered revocation_endpoint. Project sign-in access tokens also name your project's data audience, https://api.terrascale.tech/v1/projects/{project}, and carry the user's trusted claims as claims; they reach no row of a database until its rules allow it. Your browser can use those access tokens directly with Rules; see Data access for your users.
Data access for your users
Project sign-in access tokens authorize row reads, live shapes and row writes as the database's Rules allow. Deploy rules first: a database without rules denies end-user access. Guests can use the same APIs when the client permits guest sign-in and the project permits public sign-up. Start with Build a todo app with no backend.
If your backend authenticates users itself, mint a custom token with POST https://auth.terrascale.tech/v1/{project}/custom-tokens. Use a project credential with auth:tokens:mint and no database restriction. The body supplies a canonical ULID user_id, an optional database ID and optional trusted claims:
json
{"user_id":"01ARZ3NDEKTSV4RRFFQ69G5FAV","claims":{"roles":["editor"]}}Return only the short-lived access_token to the browser. Custom tokens last at most five minutes; the backend mints another when needed. Keep the minting credential on your server because it can act as any user in the project. The same rules apply to custom tokens and project sign-in tokens. Neither authorizes end-user SQL or rules management. See custom tokens for the complete data access flow.
Run the sample app
A runnable browser app implementing this whole flow lives in examples/oidc-customer-app: authorization, callback with state and nonce checks, PKCE (S256), ID token validation against the issuer JWKS, token refresh and sign-out, all discovery-based. To run it:
sh
cd sites/docs/examples/oidc-customer-app
npm install
npm startCopy .env.example to .env first and fill in your project issuer and OAuth client ID; see the example's README.
Manage users
The dashboard lists your project's users with search. For each user you can see their sessions, end a session, disable them or delete them. Disabling a user ends every session and stops their refresh tokens at once; access tokens already issued stay valid until they expire, at most 5 minutes. Deleting a user removes the account; the address can sign up again.
For automation, the .NET SDK project administration client, TerraScaleAuthClient.Projects, exposes settings read/update, provider set/delete, user list/get/disable/enable/delete, session list/revoke and OAuth client list/create/update/delete with secret rotation. These /v1/{project} calls use your TerraScale account sign-in token, with viewer access for reads and admin for changes, not a project end-user token. This is separate from interactive OIDC login; other SDKs do not necessarily expose this management group. See C# source installation for the SDK. The JavaScript SDK exposes the same routes through tsAuth.projects (@terrascale/sdk/ts-auth, sdk/js/src/ts-auth-projects.js): getSettings, updateSettings, listUsers, getUser, disableUser, enableUser, deleteUser, exportUsers, setProvider and deleteProvider (configured providers are listed in the settings), listSessions, revokeSession, listClients, createClient, updateClient, rotateClientSecret and deleteClient, each taking the sign-in token and project id; the client write operations also take a step-up proof. The Python SDK exposes the same routes on the TerraScale client (terrascale, sdk/python/src/terrascale/auth.py): get_settings, update_settings, list_users, get_user, disable_user, enable_user, delete_user and export_users, plus set_provider, delete_provider, list_sessions and revoke_session, sent with the sign-in token as the client bearer token. The Rust SDK exposes the full group through TerraScaleClient::projects() (terrascale crate, sdk/rust/src/auth_projects.rs): get_settings, update_settings, set_provider, delete_provider, list_users, get_user, disable_user, enable_user, delete_user, export_users, list_sessions, revoke_session, list_clients, create_client, update_client, rotate_client_secret and delete_client, with the sign-in token and project id passed per call; the client write operations also take a step-up proof.
Export the directory
Project admins export the directory with GET /v1/{project}/users/export. Each request needs your TerraScale sign-in token and the admin role. Each page is recorded in the organization audit log as project.users_exported before its data is returned.
limit: 1 to 100, default 100.format:json(default) orcsv.after: the previous page's cursor, fromnextin the JSON body or theX-Export-Nextheader. Omit it on the first page.
A JSON page has items, next and created_before. Both formats send the cutoff in X-Export-Created-Before. Repeat the request with after until the response has no X-Export-Next header. Save each page before you request the next one, and deduplicate by id, because a retried page may show updated fields.
bash
# TERRASCALE_ACCESS_TOKEN comes from your secret manager, never a command-line argument.
api() { curl -sS --fail-with-body -H @<(printf 'Authorization: Bearer %s\n' "$TERRASCALE_ACCESS_TOKEN") "$@"; }
api -G "https://auth.terrascale.tech/v1/$PROJECT/users/export" --data-urlencode limit=100 > page-1.jsonThis is a creation-cutoff scan, not a transaction snapshot. Accounts created at or after the first page's cutoff are left out. Deleted accounts disappear, and each page reads profile fields when it is fetched. Concurrent identity changes and clock skew at account creation can omit accounts. For a reconciled copy, pause identity changes and let them settle before the first page, then compare with the admin user list.
Each user has id (a stable ULID), email, email_verified (always true: possession was proven at account creation), created_at, disabled (disabled users are included) and linked_providers (provider, client_id and subject). Nothing else is exported: no password or hash, MFA or recovery material, session, token, key or application metadata. Importing the directory elsewhere carries over no credentials or sessions.
In CSV, linked_providers is a JSON array in one quoted cell. A cell that starts with ', =, +, -, @, a tab, CR or LF gets one extra leading apostrophe to stop spreadsheet formulas. On import, remove one leading apostrophe from any cell that starts with one. JSON keeps exact values.
Current limits
- Verification, sign-in and password-reset emails use your project's name, logo, theme color and
email_message. They are still sent from TerraScale's verified sender, with TerraScale's security copy and footer. Custom sender domains and your own mail credentials are not supported.