Feature: Play Integrity API integration (playintegrity/v1)
Summary
Add server-side Play Integrity API support to decode and inspect integrity tokens, write device recall bits, and decode PC integrity tokens, giving developers a CLI-native way to verify that requests originate from genuine, unmodified apps on trusted devices.
Why this is applicable to Google Play
The Play Integrity API is Google's recommended mechanism for protecting apps against tampering, sideloading, and abuse. Server-side token decoding is the critical backend step: the Android client obtains an integrity token, sends it to the developer's server, and the server calls Google's decodeIntegrityToken endpoint to get the verdict. This CLI already covers purchase verification (gplay purchases), and integrity verification is the natural complement -- both are server-side validation workflows that developers need to automate and script.
Problem
Developers currently have no CLI tool for decoding Play Integrity tokens. They must write custom scripts, use curl with manual OAuth token management, or navigate the Cloud Console. This creates friction in:
- CI/CD pipelines that need to validate integrity verdicts as part of automated testing
- Incident response where an engineer needs to quickly decode a suspicious token
- Server-side debugging when investigating why a client is receiving unexpected verdicts
- Device recall management for fraud prevention workflows
Goals
- Expose all three Play Integrity API endpoints:
decodeIntegrityToken,decodePcIntegrityToken, anddeviceRecall.write - Follow existing CLI patterns (ffcli, flag-based, JSON-first output)
- Use a dedicated
integrityclientpackage with theplayintegrityOAuth scope - Provide clear verdict interpretation in table/markdown output modes
- Support
--dry-runfor safe exploration
Proposed Commands
Decode an Android integrity token
gplay integrity decode \
--package com.example.app \
--token <integrity-token>
Flags:
--package(required): Package name (applicationId). Falls back to config/env.--token(required): The integrity token obtained from the client-side Play Integrity API.--output json|table|markdown(default:json): Output format.--pretty: Pretty-print JSON output.
JSON output: the full TokenPayloadExternal payload (requestDetails, appIntegrity, deviceIntegrity, accountDetails, environmentDetails, testingDetails).
Table output: a summarized view showing verdict labels, e.g.:
FIELD VERDICT
App Recognition PLAY_RECOGNIZED
Device Recognition MEETS_DEVICE_INTEGRITY, MEETS_STRONG_INTEGRITY
App Licensing LICENSED
Play Protect NO_ISSUES
App Access Risk KNOWN_INSTALLED
Recent Device Activity LEVEL_1
Package Name com.example.app
Version Code 42
Request Timestamp 2025-01-06T12:34:56Z
Decode a PC integrity token
gplay integrity decode-pc \
--package com.example.app \
--token <pc-integrity-token>
Flags: same as decode above.
JSON output: the full PcTokenPayloadExternal payload (accountDetails, deviceIntegrity, requestDetails, testingDetails).
Write device recall bits
gplay integrity device-recall write \
--package com.example.app \
--token <integrity-token> \
--bit-first true \
--bit-second false \
--bit-third true
Flags:
--package(required): Package name.--token(required): A fresh integrity token from the client (required for device identification).--bit-first(optional): Value for the first recall bit (true/false).--bit-second(optional): Value for the second recall bit (true/false).--bit-third(optional): Value for the third recall bit (true/false).--output json|table|markdown(default:json).--pretty: Pretty-print JSON output.
At least one --bit-* flag must be provided.
Command group structure
gplay integrity # group: show help
gplay integrity decode # decode Android integrity token
gplay integrity decode-pc # decode PC integrity token
gplay integrity device-recall # subgroup: show help
gplay integrity device-recall write # write device recall bits
Implementation Details
API Endpoints
| Method | REST Endpoint | Go Method |
|---|---|---|
| Decode token | POST v1/{packageName}:decodeIntegrityToken |
V1Service.DecodeIntegrityToken() |
| Decode PC token | POST v1/{packageName}:decodePcIntegrityToken |
V1Service.DecodePcIntegrityToken() |
| Write device recall | POST v1/{packageName}/deviceRecall:write |
DeviceRecallService.Write() |
Authentication
- OAuth scope:
https://www.googleapis.com/auth/playintegrity(defined asplayintegrity.PlayintegrityScopein the Go library) - This is a different scope from
androidpublisherused by the rest of the CLI. The new client must request this scope specifically. - The service account must have the Play Integrity API enabled in its Google Cloud project, and the Cloud project must be linked to the app in Play Console.
New packages and files
| Path | Purpose |
|---|---|
internal/integrityclient/client.go |
Authenticated playintegrity.Service constructor (mirrors reportingclient/client.go pattern) |
internal/cli/integrity/integrity.go |
Command group registration and decode subcommand |
internal/cli/integrity/decode_pc.go |
decode-pc subcommand |
internal/cli/integrity/device_recall.go |
device-recall subgroup and write subcommand |
internal/cli/integrity/integrity_test.go |
CLI-level tests (flag validation, output shape) |
Client implementation notes
- Follow the
reportingclientpattern: createintegrityclient.Servicewrappingplayintegrity.Servicewith the same credential resolution logic (profile, env, service account, OAuth). - The scope must be
playintegrity.PlayintegrityScope(https://www.googleapis.com/auth/playintegrity), not the androidpublisher scope. - Wrap transport with
shared.DryRunTransportwhen--dry-runis active (bothdecodeanddevice-recall writeare POST requests). - Use
shared.ContextWithTimeoutfor all API calls.
Go client library
The google.golang.org/api module (already at v0.272.0 in go.mod) includes playintegrity/v1. No new top-level dependency needed -- just import google.golang.org/api/playintegrity/v1.
Output format considerations
- JSON (default): Return the raw API response payload, minified. With
--pretty, indent it. - Table: For
decode, flatten the nested verdict into a two-columnFIELD / VERDICTtable. Map enum values to human-readable labels where helpful (e.g.,MEETS_DEVICE_INTEGRITYis already clear). Show arrays as comma-separated values. - Markdown: Same structure as table but in markdown format.
- For
device-recall write, JSON output is theWriteDeviceRecallResponse(empty on success); table output shows a success confirmation message.
Registration
Add integrity.IntegrityCommand() to internal/cli/registry/registry.go in the Subcommands function.
Acceptance Criteria
- [ ]
gplay integrity decode --package <pkg> --token <tok>decodes an Android integrity token and prints the full verdict payload. - [ ]
gplay integrity decode-pc --package <pkg> --token <tok>decodes a PC integrity token and prints the PC verdict payload. - [ ]
gplay integrity device-recall write --package <pkg> --token <tok> --bit-first truewrites device recall bits. - [ ] All commands validate required flags and return actionable error messages on missing input.
- [ ] JSON output matches the raw API response shape; table output presents a human-readable summary.
- [ ]
--dry-runintercepts the POST requests and logs them to stderr without executing. - [ ]
--prettyflag works for JSON output on all subcommands. - [ ]
integrityclientuses theplayintegrityOAuth scope, notandroidpublisher. - [ ] CLI-level tests cover flag validation, required-flag errors, and output format switching.
- [ ] Unit tests cover client construction and mock API responses.
- [ ]
gplay integrity --helpand all subcommand--helpoutput is consistent with CLI conventions (usesshared.DefaultUsageFunc). - [ ] Command is registered in
registry.go.
References
Implementation Checklist
Command & Registration
- [ ] Command group
gplay integrityininternal/cli/integrity/ - [ ] Subcommands:
decode,token create,token manage - [ ] Registered in
internal/cli/registry/registry.go - [ ]
UsageFunc: shared.DefaultUsageFuncset on all commands - [ ] Dedicated client wrapper for
playintegrity/v1API - [ ] Required flags validated with stderr error messages
Tests
- [ ] CLI black-box tests in
internal/cmdtest/integrity_test.go - [ ] Unit tests for token decoding/verdict parsing
- [ ] Error paths: missing
--package, invalid token format, missing--token
Docs & Help
- [ ]
--helpoutput follows existing conventions - [ ] Command docs regenerated:
gplay docs generate
Validation (before opening PR)
make format
make lint
make test
make build
/tmp/gplay integrity --help
/tmp/gplay integrity decode --help
/tmp/gplay integrity decode # missing required flags → stderr error
/tmp/gplay integrity decode --token bad # invalid token
Addendum to checklist above — docs CI gate:
The PR CI now runs make check-docs on every PR. This means:
- After implementing the command, run
make docsto regenerateGPLAY.md - Commit the updated
GPLAY.mdalongside your code changes - If you forget, the PR check will fail with: "GPLAY.md is out of date"
This ensures every user-facing command, flag, and help text is always reflected in the reference docs.
Consolidating individual feature requests into the roadmap so new visitors see a clean tracker. This item is on the roadmap: #245 — please 👍 there and comment which item you're waiting on. Reopen or file a fresh issue if you start on a PR.