---
title: "Add App Store and Google Play publishing to your platform"
description: "Let your users ship their apps to the App Store and Google Play without leaving your product."
sidebar:
  label: "Publish to the stores"
  order: 3
---

Your users connect their Apple and Google developer accounts once. From then on, a publish button in your product has your backend sign, build, upload, and track each release on Limrun.

## What a connected account unlocks

Connecting the developer account once gives your platform the signing material and store authorization this guide uses to:

- **Sign release builds.** Let Apple keep a cloud-managed iOS certificate, or store a distribution certificate and profile in your own secret store. Sign Play-ready AABs with the app's Android upload key.
- **Publish new builds.** Upload iOS builds to App Store Connect and TestFlight, and publish Android builds to Google Play's internal track.

The same connection can also back device installs over WebUSB or a QR code, store reporting, and listing management through the store APIs; this guide does not implement those.

:::note
  The runnable reference is [`typescript-sdk/examples/publish-to-stores`](https://github.com/limrun-inc/typescript-sdk/tree/main/examples/publish-to-stores). It includes a React frontend, an Express backend, both store flows, and an authenticated build-completion webhook.
:::

## Authenticate from the CLI

To connect store accounts from the CLI, see [Connect store accounts](/guides/store-authentication). It covers `lim ios apple auth` and `lim android play auth`, which save credentials in your organization's secret storage, and builds that read those credentials themselves.

For embedded account connection, both `@limrun/apple-auth` and
`@limrun/play-auth` use the same package imports in browsers and Node.js desktop
processes. Apple exposes `startAppleIDLogin`; the original
`startBrowserOwnedAppleIDLogin` name remains an alias. Google exposes
`authenticateGoogleDesktop` and `refreshGoogleAccessToken` for persistent Desktop
OAuth, while browser integrations continue to use `requestGoogleAccessToken`.
The packages leave credential storage to your application.

## What your platform needs

Before implementing either store flow, prepare:

- A Limrun API key in your backend's `LIM_API_KEY` environment variable.
- The `lim` CLI installed on the backend worker that starts builds.
  - Alternatively, use the TypeScript SDK clients directly to sync and trigger builds.
- App source available to that worker at a local project path.
- A durable secret store for API keys, Android upload keystores, and any manually managed Apple certificates and provisioning profiles.
- A public HTTPS webhook endpoint for build completion.
  - You can also follow the logs live, or poll after starting the build.
- A browser frontend for the Apple and Google account connection flows.

The example uses JSON files for secrets and an in-memory map for publish status. Both are demo implementations; replace them with your secret manager and database.

## 1. Build the shared backend

Both stores use the same backend responsibilities.

1. **Keep the Limrun API key on the backend**

    Create the Limrun client only in trusted server code. The frontend never needs the organization API key.

    ```ts
    import Limrun from '@limrun/api';

    const limrun = new Limrun({
      apiKey: process.env.LIM_API_KEY,
    });
    ```

    For Apple connection, mint a short-lived token scoped to the Apple relay and return that token to the browser:

    ```ts
    const session = await limrun.accessTokens.create({
      permissions: ['applerelay:*:connect'],
    });

    res.json({
      token: session.token,
      expiresAt: session.expiresAt,
      registryUrl: 'https://registry.limrun.com',
    });
    ```

    See the example's [`POST /session` route](https://github.com/limrun-inc/typescript-sdk/blob/main/examples/publish-to-stores/backend/index.ts).

2. **Implement signing-secret storage**

    `@limrun/apple-auth` and `@limrun/play-auth` both accept the same `SigningSecretStore` shape:

    ```ts
    interface SigningSecretStore {
      put(type: string, name: string, data: Record<string, string>): Promise<SigningSecret>;
      get(type: string, name: string): Promise<SigningSecret | undefined>;
      list(): Promise<SigningSecretMetadata[]>;
      delete(type: string, name: string): Promise<void>;
    }
    ```

    Back this interface with your existing database, KMS, or secret manager. Keep the names stable because later publish requests use them to resolve credentials:

    - Apple distribution certificate: `<teamId>/DISTRIBUTION`
    - App Store Connect API key: `<teamId>/APP_STORE_CONNECT_API_KEY`
    - Apple provisioning profiles: metadata includes the team ID and bundle ID
    - Android upload keystore: `<packageName>/UPLOAD`

    The example's [`SigningSecretStore` adapter](https://github.com/limrun-inc/typescript-sdk/blob/main/examples/publish-to-stores/frontend/src/lib/secret-store.ts) and [file-backed implementation](https://github.com/limrun-inc/typescript-sdk/blob/main/examples/publish-to-stores/backend/secret-store.ts) show the complete request and response shapes.

3. **Expose an authenticated completion webhook**

    A detached build finishes after the initial CLI process exits. Give each publish a random token and pass it as a custom webhook header:

    ```ts
    const publishId = crypto.randomUUID();
    const webhookToken = crypto.randomBytes(32).toString('hex');

    const callbackArgs = [
      '--webhook-url', publicWebhookUrl,
      '--webhook-header', `X-Publish-Token=${webhookToken}`,
      '--detach',
      '--json',
    ];
    ```

    Store the token with the publish record. When Limrun calls the webhook, compare `X-Publish-Token`, persist the payload, and mark the publish as succeeded or failed. The callback URL must be publicly reachable over HTTPS; do not expose your secret-store or token-minting routes with it. [Build logs and webhooks](/ci/build-logs-and-webhooks) documents the payload and delivery rules.

    The example runs the [webhook receiver](https://github.com/limrun-inc/typescript-sdk/blob/main/examples/publish-to-stores/backend/index.ts) on a separate port and performs [constant-time token matching](https://github.com/limrun-inc/typescript-sdk/blob/main/examples/publish-to-stores/backend/publish.ts).

## 2. Add App Store connection

The user needs an Apple Developer Program account with permission to create App Store Connect API keys. Let them choose who maintains the signing certificate:

- **Apple cloud signing** uses only the App Store Connect API key. Apple creates, retains, and reuses the cloud-managed distribution certificate and provisioning profile.
- **Manual signing** creates and stores the distribution certificate and App Store provisioning profile in your secret store. Your application is responsible for renewing and replacing them.

Both modes prepare an App Store Connect app record and API key for the upload.

1. **Sign the user in with Apple**

    In the browser, initialize `useAppleIDLogin` with the access token returned by your backend:

    ```tsx
    import { useAppleIDLogin } from '@limrun/apple-auth/react';

    const appleLogin = useAppleIDLogin({
      registryApiUrl: session.registryUrl,
      token: session.token,
    });

    const result = await appleLogin.startLogin({
      accountName,
      password,
    });
    ```

    If `result.requiresTwoFactor` is true, collect the verification code and call `appleLogin.submitTwoFactorCode(code)`. After authentication, call `finalize()` and list the account's teams with `listAppleTeams`.

    See [Apple Account authentication](/platform/apple-authentication) for the SRP password exchange, six-digit verification code, and WebSocket relay traffic. The example implements this state machine in [`useConnect.ts`](https://github.com/limrun-inc/typescript-sdk/blob/main/examples/publish-to-stores/frontend/src/hooks/useConnect.ts).

2. **Select or register the bundle ID**

    List the selected team's explicit bundle IDs with `listAppleBundleIDs`. Let the user select an existing ID or register one with `createAppleBundleID`.

    Ask for the app's display name at the same time. It is required when you create the App Store Connect app record.

3. **Choose a signing mode and prepare credentials**

    Run these actions after the user confirms the team, bundle ID, and signing mode:

    1. Switch to the team's App Store Connect provider when the team has a provider ID.
    2. Call `ensureAppStoreConnectApp` for the bundle ID and app name.
    3. Call `ensureAppStoreConnectApiKeySecret` and save the result.
    4. For manual signing, call `ensureAppleCertificateSecret`, create or refresh an App Store provisioning profile that references that certificate, and store the profile.

    Cloud signing requires the App Store Connect team key to be an Admin key or have **Access to cloud-managed distribution certificates** enabled. Limrun uses the key for cloud signing and upload; manual mode uses it for upload only. Reuse valid stored resources when the user reconnects. [Sign and distribute](/ios/sign-and-distribute) explains both signing modes in detail.

## 3. Publish the iOS app

When the user clicks publish, send the project path, team ID, bundle ID, signing mode, optional scheme, and webhook URL to your backend.

The backend then:

1. Loads the App Store Connect API key from the secret store.
2. For manual mode, also loads the distribution certificate and App Store provisioning profile.
3. Writes the selected credentials to a temporary directory with owner-only permissions.
4. Starts a release build for the target Apple device SDK with either cloud or manual signing flags.
5. Requests automatic build-number selection, upload to App Store Connect, a completion webhook, and detached JSON output.
6. Deletes the temporary files after the CLI exits.

The cloud-signing invocation has this shape:

```bash
lim xcode build <project-path> \
  --sdk iphoneos \
  --configuration Release \
  --signing-method app-store-connect \
  --team-id <team-id> \
  --upload-to-appstore \
  --auto-build-number \
  --asc-key-id <key-id> \
  --asc-issuer-id <issuer-id> \
  --asc-key <AuthKey.p8> \
  --webhook-url <public-https-url> \
  --webhook-header "X-Publish-Token=<random-token>" \
  --inactivity-timeout 3s \
  --detach \
  --json
```

Manual mode replaces `--signing-method` and `--team-id` with:

```bash
--certificate-p12 <certificate.p12> \
--certificate-password <password> \
--provisioning-profile <profile.mobileprovision>
```

The upload still uses the `--asc-*` flags. Add `--scheme <scheme>` when the project needs one. For tvOS or visionOS, use `--sdk appletvos` or `--sdk xros` with the matching scheme and App Store Connect app record. Cloud signing requires a team API key and its issuer ID. Spawn the CLI with an argument array instead of constructing a shell command, and redact the certificate password from logs.

Both signing modes include the app's symbols in the IPA, so App Store Connect symbolicates crash reports for the build. This needs dSYMs from the build, which the Release configuration produces by default (`DEBUG_INFORMATION_FORMAT=dwarf-with-dsym`).

The complete implementation is in [`startPublish`](https://github.com/limrun-inc/typescript-sdk/blob/main/examples/publish-to-stores/backend/publish.ts). A successful upload appears in App Store Connect and TestFlight. The user still attaches the processed build to an App Store version and submits that version for review in App Store Connect.

## 4. Add Google Play connection

Google requires the Play Console app listing to exist before publishing. With ordinary `androidpublisher` access, ask the user to create the listing with the exact Android package name and grant their Google account release permission.

The source example also includes an experimental **Create app** button using `createPlayConsoleApp` and `enrollPlayAppSigning` from `@limrun/play-auth`. It requires Google to approve your OAuth client for `https://www.googleapis.com/auth/play_console` or `https://www.googleapis.com/auth/playdeveloperapp`. Set `GOOGLE_PLAY_CONSOLE_SCOPE` in the example's `frontend/src/config.ts` to the scope Google approved, then sign in again. Leave it empty for ordinary publishing. Requesting either scope without approval returns `invalid_scope`; adding it to the request does not grant access.

This OAuth creation flow has not been verified end to end with an approved client. The form requires the developer account ID and both policy declarations. It creates a free Android app and requests Play App Signing enrollment. If enrollment fails, retain the returned app ID and retry enrollment only. If creation reports an unknown outcome, check the developer account before repeating it. See the [package's experimental app creation guide](https://github.com/limrun-inc/typescript-sdk/tree/main/packages/play-auth#experimental-app-creation) for the API and recovery behavior.

1. **Configure Google browser sign-in**

    Create a Google OAuth Web application client whose authorized JavaScript origins include your frontend origin. Pass its client ID to `requestGoogleAccessToken`:

    ```ts
    import { requestGoogleAccessToken } from '@limrun/play-auth';

    const accessToken = await requestGoogleAccessToken({
      clientId: GOOGLE_OAUTH_CLIENT_ID,
    });
    ```

    Keep the access token in browser memory. Send it to your backend only with a publish request, and ask the user to sign in again after it expires.

2. **Resolve and verify the package name**

    Read `expo.android.package` from Expo projects or `applicationId` from `app/build.gradle` and `app/build.gradle.kts`. Let the user correct the detected value.

    Use the Google token to verify that the listing exists and that the account can access it. If the listing is missing, link the user to Play Console and retry after they create it. The example contains both [package detection](https://github.com/limrun-inc/typescript-sdk/blob/main/examples/publish-to-stores/backend/publish-android.ts) and the [browser connection state](https://github.com/limrun-inc/typescript-sdk/blob/main/examples/publish-to-stores/frontend/src/hooks/usePlay.ts).

3. **Store the Play upload keystore**

    First check your secret store for `<packageName>/UPLOAD`.

    - For an app that already has an upload key, import that keystore and its alias and passwords.
    - For a new app, call `generateAndroidUploadKeystore(packageName)` and store the returned values.
    - Never replace an existing upload keystore without an explicit key-reset process. Future uploads signed by a different key will be rejected.

    The stored data contains `keystoreBase64`, `keystorePassword`, `keyAlias`, and `keyPassword`. The example's [`usePlay` hook](https://github.com/limrun-inc/typescript-sdk/blob/main/examples/publish-to-stores/frontend/src/hooks/usePlay.ts) checks again immediately before storing so concurrent requests cannot overwrite a key.

## 5. Publish the Android app

Send the project path, package name, Google access token, and webhook URL to your backend. The reference flow publishes to the internal track.

The backend then:

1. Loads `<packageName>/UPLOAD` from the secret store.
2. Writes the keystore to a temporary owner-only file.
3. Passes keystore and key passwords through environment variables.
4. Starts a release AAB build with automatic `versionCode` selection.
5. Publishes the AAB to Google Play's internal track.
6. Deletes the temporary file after the CLI exits.

The invocation has this shape:

```bash
LIM_KEYSTORE_PASSWORD=<keystore-password> \
LIM_KEY_PASSWORD=<key-password> \
LIM_PLAYSTORE_ACCESS_TOKEN=<google-access-token> \
lim gradle build <project-path> \
  --keystore <upload-keystore> \
  --key-alias <alias> \
  --upload-to-playstore \
  --playstore-package <package-name> \
  --playstore-track internal \
  --auto-version-code \
  --webhook-url <public-https-url> \
  --webhook-header "X-Publish-Token=<random-token>" \
  --inactivity-timeout 3s \
  --detach \
  --json
```

The reference UI supports only the `internal` track. Its backend accepts another track value, but it does not expose the release-status handling required for a complete production-track flow. Add that handling before offering other tracks in your product. The full internal-track implementation is in [`startAndroidPublish`](https://github.com/limrun-inc/typescript-sdk/blob/main/examples/publish-to-stores/backend/publish-android.ts).

## 6. Return progress to the frontend

The initial publish endpoint should return as soon as the detached build is accepted:

```json
{
  "publishId": "01k..."
}
```

Store at least `publishId`, state, start time, webhook token, and the Limrun Console URL returned by the CLI's detached JSON output. Your frontend can poll a status endpoint or subscribe to your own event stream while the build runs.

When the authenticated webhook arrives:

1. Match it to the publish using the webhook token.
2. Store the payload and its receipt time.
3. Treat `status: "SUCCEEDED"` as success and other terminal statuses as failure.
4. Surface `consoleUrl` and `logsUrl` when present. Use the persisted log for failure diagnostics.

The example's [`usePublish`](https://github.com/limrun-inc/typescript-sdk/blob/main/examples/publish-to-stores/frontend/src/hooks/usePublish.ts) and [`usePlay`](https://github.com/limrun-inc/typescript-sdk/blob/main/examples/publish-to-stores/frontend/src/hooks/usePlay.ts) poll every three seconds. Its backend map is process-local, so restarting the example loses active publish records. Persist these records in your platform.

## Get a support reference for Apple login failures

With `@limrun/apple-auth`, display the `relaySessionId` returned by
`useAppleIDLogin()` next to the login error. The hook retains this reference even
when login fails before it returns a session. Starting another login or calling
`close()` clears it.

If you call `startBrowserOwnedAppleIDLogin()` directly, catch `AppleRelayError`
and read `error.relaySessionId`. After a successful login, read
`login.relay.relaySessionId`. Low-level relay responses also include
`response.relaySessionId`.

Give Limrun support this reference and the approximate failure time. The reference
identifies one connection, contains no account information, and grants no access.
A new connection gets a new reference. Avoid recording whole Apple responses,
headers, or error messages, which can contain account information or authentication
state.

The reference is optional. Older relay servers do not provide it, and a connection
that fails before its first response has no reference.

## Production checklist

- Keep `LIM_API_KEY` and signing secrets out of the browser.
- Give the browser only a short-lived Apple relay token.
- Keep Google access tokens in memory and avoid logging them.
- Encrypt stored certificates, private keys, profiles, keystores, and passwords.
- Do not expose secret-store endpoints to the public internet.
- Authenticate and correlate every completion webhook.
- Persist publish state before starting the detached build.
- Delete materialized credential files after the CLI exits.
- Preserve existing Android upload keys and Apple credentials across publishes.
- Show users the Limrun Console and persisted log links for failed builds.

## Run the reference implementation

The example requires Node.js and Yarn 1. Clone the [TypeScript SDK repository](https://github.com/limrun-inc/typescript-sdk), then install and start both halves:

```bash
export LIM_API_KEY="lim_..."

yarn --cwd examples/publish-to-stores/backend install
yarn --cwd examples/publish-to-stores/frontend install
yarn --cwd examples/publish-to-stores/backend dev
```

In another terminal:

```bash
yarn --cwd examples/publish-to-stores/frontend dev
```

Run a public HTTPS tunnel to the webhook receiver on port `3001`, paste that URL into the UI, and open `http://localhost:5173`. The [example README](https://github.com/limrun-inc/typescript-sdk/blob/main/examples/publish-to-stores/README.md) covers its local ports, webhook behavior, secret-directory sharing, and both store tabs.

## Next steps

**[Sign and distribute](/ios/sign-and-distribute)**

Manual and cloud signing, entitlements, and App Store Connect uploads in depth.

**[Sign and publish](/android/sign-and-publish)**

Upload keys, release AABs, and Google Play version codes.

**[Build logs and webhooks](/ci/build-logs-and-webhooks)**

The webhook payload, delivery rules, and persisted build logs.
