> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bbrands.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Operations and maintenance

> Day-to-day operations: turning providers on or off, rotating the Apple secret and the keyrings, the mandatory release, how to roll back and how to troubleshoot.

This page is for after the [rollout](https://docs.bbrands.io/maihuego/authentication/setup.md). It covers the recurring tasks
and what to do when something fails. The source of truth for every console is still the runbook
[`docs/operations/oauth-providers.md`](https://github.com/bbrandslab/bbrands-monorepo/blob/develop/docs/operations/oauth-providers.md).

## Turn a provider on or off

Each provider has a single flag for every platform (ADR 0133), in the `authenticate` category:
`authenticate-oauth-google`, `authenticate-oauth-apple` and `authenticate-oauth-microsoft`.

**1. Open Capacidades**

Horizon Enterprise of the environment → **Capacidades** → category `authenticate`.

**2. Change the flag**

Turn the provider's flag on or off and leave a comment naming the reason and the runbook.

**3. Wait for the next evaluate**

The change takes effect at each client's next evaluate, with no release. The app evaluates when it
opens and when it returns to the foreground; the web evaluates on the server; horizon-api stops
listing the provider in the `providers` of `verify-email`. If someone still sees the old state in
the app, they should force-close it and open it again.

E-mail sign-in and the magic link keep working with any combination of flags. To see the current
state:

```bash theme={null}
curl -s "https://api.bbrands.io/api/v3/feature-flag/evaluate?category=authenticate"
```

> [!WARNING]
>
> If the backend is rolled back to a version older than 2026.11.3, **do not run Sync** in
> Capacidades: the old catalogue would delete the `authenticate-oauth-*` flags and recreate the old
> keys turned off.

## Rotate the Apple secret every six months

Supabase's Apple provider uses an ES256 JWT as its secret, valid for **at most 6 months**. When it
expires, the browser flow (Android and web) fails; native iOS keeps working. horizon-api builds its
own secret on every call from the `.p8`, so it needs no rotation while the key is valid.

**1. Generate the JWT on a trusted machine**

With Node and `jose`, never in CI. Use the environment's Services ID:

```bash theme={null}
APPLE_TEAM_ID=… APPLE_KEY_ID=… SERVICES_ID=com.maihuego.signin.cert \
node --input-type=module -e '
import { SignJWT, importPKCS8 } from "jose";
import { readFileSync } from "node:fs";
const key = await importPKCS8(readFileSync(process.argv[1], "utf8"), "ES256");
const now = Math.floor(Date.now() / 1000);
console.log(await new SignJWT({})
  .setProtectedHeader({ alg: "ES256", kid: process.env.APPLE_KEY_ID })
  .setIssuer(process.env.APPLE_TEAM_ID)
  .setSubject(process.env.SERVICES_ID)
  .setAudience("https://appleid.apple.com")
  .setIssuedAt(now)
  .setExpirationTime(now + 15_552_000)
  .sign(key));
' ./AuthKey_XXXXXXXXXX.p8
```

`15_552_000` seconds are 180 days.

**2. Paste it in Supabase**

Authentication → Sign In / Providers → **Apple** → **Secret Key (for OAuth)** → Save.

**3. Record and schedule**

Write the date in the runbook table (in a PR) and create a reminder **five months later** for
Backend Platform: "Rotate the Supabase Apple secret, `environment`".

> [!TIP]
>
> Rotating the secret signs nobody out.

## Rotate the keyrings

| Keyring | Steps |
| - | - |
| `AUTH_PROVIDER_TOKEN_KEYRING` | 1. Add a new key to the JSON and mark it `active`. 2. Keep the previous one: each `auth_provider_credential` row is re-encrypted when its login signs in with Apple again. 3. Remove the previous key only when no row is sealed with it. |
| `AUTH_GOTRUE_BRIDGE_KEYRING` | 1. Add a new key as current. 2. Values are rewritten on sign-in or refresh, plus a pass over the live Redis values. 3. Keep the previous one until no value uses it or 30 days, whichever is later. |

In both cases: change the value in the horizon-api 1Password Environment, run **Sync Env** and deploy
(a Sync does not rebuild the app). Never reuse one keyring for the other.

## Mandatory release

It is turned on **only** when 2026.11.3 is published in both stores. That way old versions, which do
not read the new flags, get updated.

**1. Turn it on**

Horizon Enterprise → MaihueGO 2026.11.3 release → App Store row and Google Play row → mandatory.
Through the API it is
`PATCH /api/v3/bbrands/application/release/store/<document_id>` with `is_mandatory: true`.

**2. Verify**

With the previous version, both answers must carry `update_required: true`:

```bash theme={null}
curl -s "https://api.bbrands.io/api/v3/bbrands/application/release/maihuego/check-mandatory?os=ios&version=<previous version>"
curl -s "https://api.bbrands.io/api/v3/bbrands/application/release/maihuego/check-mandatory?os=android&version=<previous version>"
```

**3. If the new version has a blocking bug**

Turn `is_mandatory` off on both rows, pause the phased release in App Store Connect and the
rollout in Play Console, and ship a fix.

## How to roll back

| Problem | Action |
| - | - |
| A provider fails (errors, provider incident, App Review question) | Turn its `authenticate-oauth-*` flag off. Effective on every platform at the next evaluate |
| The Apple browser flow fails after months | The Supabase secret expired: regenerate it and paste it |
| Mail to the private relay bounces | Check the domain registration in Apple (missing sender or return-path, or SPF fails) |
| Apple notifications fail (4xx or 5xx in logs) | Fix forward. Last resort: clear the endpoint on the primary App ID; sign-in does not depend on it, but revoked consents and relay changes are missed meanwhile |
| The backend must be rolled back | Redeploy the previous release **without running Sync**. The migration is additive and stays |
| The new app has a blocking bug while the release is mandatory | Turn `is_mandatory` off, pause the phased release and the rollout, ship a fix |

> [!WARNING]
>
> Never delete Apple keys, Services IDs or relay registrations on rollback. Revoking a key breaks the
> browser flow, the code exchange and token revocation for that environment.

## Troubleshooting

| Symptom | Likely cause | Fix |
| - | - | - |
| `429` on web sign-in for everyone after a few attempts | `AUTH_BFF_SERVER_TOKEN` is missing in horizon-authenticate or differs from horizon-api's | Load the same value, run Sync Env for horizon-authenticate and redeploy |
| Apple fails on Android and web, but not on iOS, months after the rollout | The Supabase Apple secret expired | [Rotate it](#rotate-the-apple-secret-every-six-months) |
| Mail to `@privaterelay.appleid.com` bounces | Sender or Resend return-path domain not registered with Apple, or SPF fails | Register the domain in Sign in with Apple for Email Communication and test with a magic link |
| Native Apple fails on iOS but works on Android | The bundle id is missing from the **Client IDs** of the Supabase Apple provider | Add every bundle id of the environment and the Services ID. In horizon-api, `APPLE_CLIENT_IDS` holds the same ids with the bundle ids first and the Services ID last, and `APPLE_SERVICES_ID` the Services ID ([Rollout](https://docs.bbrands.io/maihuego/authentication/setup.md)) |
| The button shows, but sign-in fails | The flag was turned on before the deploy or before the consoles were configured | Turn the flag off, finish the deploy and consoles, turn it on again |
| An old app shows no provider | Versions older than 2026.11.3 do not read the `authenticate-oauth-*` flags | Expected: the mandatory release forces the update |
| A fresh install shows no providers for a moment | There is no successful evaluate yet; the app shows no provider without one | Wait for the evaluate or reopen the app |
| Apple notifications answer 4xx | Invalid JWS or audience outside `APPLE_CLIENT_IDS` (`400`), or more than 20 events in 10 min per subject (`429`) | Check `APPLE_CLIENT_IDS` and the endpoint on the primary App ID |
| `423` on password sign-in | Lockout after 5 failed attempts in 15 min | Wait 15 min or unlock with `POST /api/v3/auth/lockout/clear` |
| `410 OAUTH_CALLBACK_UPGRADE_REQUIRED` | An old client sends the tokens in the query | Update the client; tokens go in the fragment |

## Where to look

* **Runbook:** `docs/operations/oauth-providers.md` (consoles, variables, rollback).
* **horizon-api runtime logs in Vercel:** search for `rate_limit_blocked`,
  `oauth_query_tokens_used` or `Apple identity token refused`.
* **Flags:** Horizon Enterprise → Capacidades, or the `evaluate` route above.
* **E-mail:** Resend → deliveries, to confirm whether a mail to the relay arrived or bounced.
* **Apple revocation:** in the test Apple ID settings, MaihueGO no longer appears after the account
  is deleted.

## Pending items

As of 2026-11-04 these `authenticate/oauth` tasks are still open:

| Task | What it is | What it means for operations |
| - | - | - |
| T-01 | Confirm that Supabase returns Apple's `provider_refresh_token` in the browser flow | If it does not, Apple logins made from Android or web would have no stored token to revoke when the account is deleted |
| T-15 | Run the manual table MT-01 to MT-11 in certification | No case is tested yet; production waits for this result |
| T-16 | Production: Google and Apple on, old keys deleted, App Review submission | The production launch state is not applied yet |
| T-17 | Mark the release mandatory once the version is in both stores | Until then, old apps keep showing no provider |

## See also

* [Rollout](https://docs.bbrands.io/maihuego/authentication/setup.md)
* [Security and limits](https://docs.bbrands.io/maihuego/authentication/security.md)
* [Sign in with Apple](https://docs.bbrands.io/maihuego/authentication/apple.md)
* [IdP, machines and events](https://docs.bbrands.io/maihuego/authentication/platform.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.