Repository navigation
Sign the example apps into WordPress.com from a launch-argument token - #1652
Merged
Merged
Conversation
crazytonyli
approved these changes
Sep 28, 2026
Collaborator
XCFramework BuildThis PR's XCFramework is available for testing. Add to your .package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1652")Built from e0a26f1 |
jkmassel
enabled auto-merge (squash)
September 28, 2026 22:31
The `.toolbar` was attached to the `NavigationView`, which drops toolbar items once it collapses to a single column on iPhone, so there was no way to sign out. Attach it to the sidebar column instead. Co-Authored-By: Claude <noreply@anthropic.com>
Adds `make example-app-login` (wrapping `scripts/example-app-signin.sh`), which launches the Swift example app on an iOS Simulator with `-wpcom-token`, or the Android example app on an emulator with a `wpcom-token` intent extra. The app stores the token as its WordPress.com account at launch, so no OAuth app credentials or taps are needed. The token is read from `WPCOM_TOKEN` or `~/.wpcom-token` (or a hidden prompt), never the command line. Modelled on wordpress-mobile/WordPress-iOS#25801. Co-Authored-By: Claude <noreply@anthropic.com>
Resolve the token from `WPCOM_TOKEN`, then the repo's `wp_com_test_credentials.json` `bearer_token` (the one the WordPress.com integration tests use), then `~/.wpcom-token`, and fail with a pointer to the credentials file otherwise. This replaces the hidden paste-and-save prompt, which assumed a developer had a token to hand but nowhere to keep it. Co-Authored-By: Claude <noreply@anthropic.com>
Prints `Using the WordPress.com token from <source>` (never the token itself), so it's clear whether `WPCOM_TOKEN`, `wp_com_test_credentials.json`, or `~/.wpcom-token` won. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
`generateWpComCredentials` emitted `client_id: 0` / `client_secret: ""` from `wp_com_test_credentials.json-example` as real credentials, enabling a WordPress.com OAuth button that can't work. The placeholders are required for a bearer-token-only file to satisfy `integration_test_credentials`, so require both values to be non-zero/non-empty or generate both as `null`, matching the Swift example app. Co-Authored-By: Claude <noreply@anthropic.com>
jkmassel
force-pushed
the
jkmassel/demo-app-wpcom-sign-in
branch
from
September 29, 2026 14:08
a2fddff to
e0a26f1
Compare
Merged
6 of 10 tasks
jkmassel
added a commit
to wordpress-mobile/GutenbergKit
that referenced
this pull request
Oct 11, 2026
* task: sign the demo apps into WordPress.com from a launch-argument token Adds `make login-ios-app` and `make login-android-app` (wrapping `bin/demo-app-login.sh`), which launch the iOS demo app on a Simulator with `-wpcom-token`, or the Android demo app on an emulator with a `wpcom-token` intent extra. The app stores the token as an account at launch, so a WordPress.com site can be added with no OAuth application and no taps. The token is read from `WPCOM_TOKEN` or `~/.wpcom-token`, never the command line. Modelled on Automattic/wordpress-rs#1652. The demo apps keep one account per site and need the site's numeric ID, so the script also looks the site up from the WordPress.com REST API — the account's primary site, or `SITE=<domain>` — and passes its ID and host as `-wpcom-site-id` and `-wpcom-site-host`. The app replaces any account it already holds for that site, so running the command again picks up a new token. The format of the stored WordPress.com API root now comes from one helper per platform, because the site ID is parsed back out of it. * task: reuse a stored WordPress.com token when adding a site to the demo apps "Add WordPress Site" started the OAuth flow for every WordPress.com site, which needs an OAuth application in `wp_com_oauth_credentials.json` even when the app already holds a token for the same user. When the entered site is on WordPress.com, look it up with each WordPress.com token the app has stored, using wordpress-rs's `sites.getSite`. The first token whose user has `edit_posts` on the site is stored as an account for it, with no login screen. Otherwise the OAuth flow runs as before. WordPress.com returns no `capabilities` for a site the token's user isn't a member of, so that lookup fails to decode and the site goes through OAuth as well. * task: boot a simulator named with DEVICE, and try stored WordPress.com tokens in stored order `make login-ios-app DEVICE=<id>` skipped the booted check, so naming a shut-down simulator failed with CoreSimulator's `code=405 … Unable to lookup in current state: Shutdown`. `bin/demo-app-login.sh` now runs `simctl bootstatus -b` on a named simulator, which boots it if it isn't running and waits until it's ready. The boot opens no window, so the app shows once the simulator is opened in Device Hub. The hint for when no simulator is running now names Device Hub, which replaced Simulator in Xcode 27. On iOS, "Add WordPress Site" walked the stored tokens through a `Set`, whose order changes between launches, so the token used varied when more than one could edit the site. It now tries them in stored order, as Android does. Suggested in review by David Calhoun.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
make example-app-login, which signs the Swift or Android example app into WordPress.com with a bearer token in one command. You don't need OAuth app credentials inwp_com_test_credentials.json, and you don't need to tap through a sign-in flow. Modelled on wordpress-mobile/WordPress-iOS#25801.The demo apps have no sign-in UI to automate (unlike the WordPress app), so the approach is simpler: the app stores the launch token as its WordPress.com account at startup.
Changes
1.
make example-app-login/scripts/example-app-signin.shcom.automattic.Examplewithsimctl launch -wpcom-token.--resetuninstalls and reinstalls the app.WelcomeActivitywitham start -S --es wpcom-token.--resetrunspm clear.The token never appears on the command line. It resolves from
WPCOM_TOKEN, thenbearer_tokenin the repo-rootwp_com_test_credentials.json(the same token the WordPress.com integration tests use), then~/.wpcom-token. If none is set, the script fails with a pointer towp_com_test_credentials.json-example. There is deliberately no--wpcom-tokenflag, because a token passed as an argument would be saved to shell history.~/.wpcom-tokencovers fresh worktrees that don't have a copy of the gitignored credentials file, and it's the same file WordPress-iOS'smake sim-loginreads.adb shelljoins its arguments into a command line that the device's shell runs, and WordPress.com tokens contain shell metacharacters (#,(,$). The script single-quotes the token before passing it.2. Launch-time sign-in in the apps
LoginManager.swift:initstores the-wpcom-tokenargument as the WordPress.com account when none is signed in. It readsProcessInfo.argumentsrather thanUserDefaults, which parses argument values as property lists.WelcomeActivity.kt: stores thewpcom-tokenextra when no global WordPress.com account exists. It runs only on a freshonCreate, and removes the extra once it's been used.Both apps read the token at most once per launch, so signing out stays signed out while the still-present token is ignored.
3. Fix: WordPress.com Sign Out button missing on iPhone
WPComRootViewattached its.toolbarto theNavigationView. ANavigationViewdrops toolbar items once it collapses to a single column on iPhone, so there was no way to sign out. The toolbar is now attached to the sidebar column.4. Fix: Android example app offered OAuth sign-in with placeholder credentials
generateWpComCredentialspassedclient_id/client_secretthrough as-is. The placeholders fromwp_com_test_credentials.json-example(0/"") therefore became non-nullWpComCredentials, and Sign in to WordPress.com was enabled with credentials that can't work. Those placeholders are also required: a file holding only abearer_tokenfails to compileintegration_test_credentialswithout them. Both values must now be non-zero/non-empty, or both generate asnull, matchingWPComOAuthCredentialsin the Swift example app.5. Docs
A new section in
Documentation/local-development.mdcovers the Makefile target, how the token is resolved, and the rawsimctl/adbforms.Test plan
make example-app-login RESET=1→ the WordPress.com tab lands signed in, and Me loads the account's profile. The UI was driven with Xcode 27's device-interaction tools.accounts.jsonholds 0 accounts.make example-app-login PLATFORM=android→ the account appears on the Sites screen with no taps, and Me loads the profile. This confirms the token's shell quoting survivesadb shell.xcrun/adbon macOS's bash 3.2: device auto-selection,--resetordering, rejection of--wpcom-tokenand unknown platforms.bearer_tokenin the repo-rootwp_com_test_credentials.json, the script reportsUsing the WordPress.com token from wp_com_test_credentials.json. Me then loads the profile on both the iOS Simulator and the Android emulator, afterRESET=1.WPCOM_TOKENwins over everything, and the credentials file wins over~/.wpcom-token. The example file's uneditedreplace_with_your_oauth2_tokenplaceholder is ignored, and with nothing configured the script exits 1 with the error.generateWpComCredentialsoutput:0/""→null/null; both set → both emitted;client_idonly →null/null; keys missing →null/null.client_id: 0/client_secret: "": Sign in to WordPress.com is disabled, with the "Add client_id and client_secret…" hint.swift format lint --strict, SwiftLint, and:example:androidApp:compileDebugKotlin :example:androidApp:detektare clean.Changelog
CHANGELOG.mdunder## [Unreleased], using the Keep a Changelog categories (Added,Changed,Deprecated,Removed,Fixed,Security). Prefix breaking changes with**BREAKING:**.