phone-number-verification
Verify user phone numbers without SMS in an Android app using the Credential
- 01Installs
- New
- 02Files scanned
- 3
Security scan
Scan passedNo risky patterns were found in the scanned files.
Content sha256 2d56ba9dfecdeb8b… — run codexguild_scan_skills after installing to verify your local copy.
Static analysis is a first line of defense, not a guarantee. Read the source
SKILL.md
Implement phishing-resistant, SMS-free phone number verification in an Android
app using Credential Manager's DigitalCredential API to request an encrypted,
carrier-issued TS.43 token over OpenID4VP and exchange it with an aggregator
or mobile carrier backend for the verified phone number. When reviewing TS.43
architecture and security standards, consult
About verifying phone numbers. When implementing client and server code
snippets, consult Implement phone number verification. When verifying
general mso_mdoc or dc+sd-jwt wallet credentials, suggest the
credential-verifier skill.
Prerequisites and setup
- Android version compatibility: Runtime support for the Phone Number Verification API requires Android 10 (API level 29) or higher (while the
androidx.credentialslibrary compiles withminSdk23 or higher). - Aggregator account: Requires an account with a mobile carrier or cellular aggregator endpoint that supplies DCQL parameters and exchanges
TS.43tokens. - Manifest permission for carrier precheck: Declare
<uses-permission android:name="android.permission.READ_PHONE_STATE" />inapp/src/main/AndroidManifest.xmlto queryTelephonyManager.getSimCarrierId()before invoking Credential Manager. - Build config permission: Ask for user confirmation before modifying
settings.gradle.kts, rootbuild.gradle.kts, orgradle/libs.versions.toml, unless already requested by the user or running non-interactively. - Dependencies and package mapping: Add the Credential Manager artifacts to the app module build script (
app/build.gradle.ktsorapp/build.gradle; when checking the latest version declarations, consult Implement phone number verification):
| Artifact | Key classes, constructor signatures, and package |
|---|---|
androidx.credentials:credentials:1.7.0-alpha03 (or 1.6.0+) | CredentialManager, GetCredentialRequest, GetCredentialResponse, GetDigitalCredentialOption(requestJson: String), DigitalCredential, and ExperimentalDigitalCredentialApi in androidx.credentials; GetCredentialException, GetCredentialCancellationException, GetCredentialInterruptedException, GetCredentialUnsupportedException, and NoCredentialException in androidx.credentials.exceptions |
androidx.credentials:credentials-play-services-auth:1.7.0-alpha03 (or 1.6.0+) | Play services provider integration for Credential Manager |
Expected inputs and file scope
- Required inputs: Whether the app is retrieving the device phone number (
number-verification/device-phone-number/ts43) or verifying an existing user-entered phone number (number-verification/verify/ts43), whether dual SIM (subscription_hint) or biometric/screen-lock verification (user_verification_hint) is needed, and the fallback verification flow when the carrier or device is unsupported. - Files to modify:
app/build.gradle.kts,app/src/main/AndroidManifest.xml(forREAD_PHONE_STATE), phone number verification client or repository classes, ViewModels, and UI screens orActivityclasses (such asMainActivity.kt). - Forbidden substitutions: Don't use
TelephonyManager.getLine1Number(),READ_PHONE_NUMBERS,SmsRetriever, or SMS OTP APIs as a substitute for the Credential ManagerDigitalCredentialTS.43 verification flow (only useTelephonyManager.getSimCarrierId()for the carrier support precheck, and fall back to SMS only when the carrier or device is unsupported).
Codebase exploration
Search the Android project before modifying files:
- Validate baseline build and inspect configuration: Run
./gradlew assembleDebugto confirm the project compiles before making changes, checkapp/build.gradle.ktsandgradle/libs.versions.tomlforminSdkandandroidx.credentialsdependencies, and checkapp/src/main/AndroidManifest.xmlforREAD_PHONE_STATE. - Locate UI entry points: Identify the
Activityor Compose screen (such asMainActivity.ktorTasksScreen.kt) where phone number verification is triggered so you pass anActivityContexttocredentialManager.getCredential().
Critical implementation mandates
Follow the end-to-end steps and code snippets in Implement phone number verification and apply these rules:
- Opt in to experimental APIs: Annotate classes or functions referencing
GetDigitalCredentialOptionandDigitalCredentialwith@OptIn(androidx.credentials.ExperimentalDigitalCredentialApi::class)(omitted from the Kotlin snippet in Implement phone number verification). - Perform the carrier TS.43 precheck and handle unsupported fallbacks: Declare
READ_PHONE_STATEinAndroidManifest.xml, querytelephonyManager.getSimCarrierId(), and check whether the user's carrier supports TS.43 with the app's aggregator backend before callingcredentialManager.getCredential(). If the carrier is unsupported, or if the device runs below Android 10 (API level 29) or throwsGetCredentialUnsupportedExceptionorGetCredentialCancellationException, trigger a fallback verification flow (such as SMS). - Configure DCQL parameters and optional hints: In each
{ ... }credential entry insiderequests[0].data.dcql_query.credentials(with"protocol": "openid4vp-v1-unsigned","response_type": "vp_token","response_mode": "dc_api", and a"nonce"matching the aggregator DCQL request):- Set
"format": "dc-authorization+sd-jwt"and includemeta.credential_authorization_jwtfrom the aggregator. - Set
meta.vct_valuesto["number-verification/device-phone-number/ts43"]to retrieve the device phone number, or["number-verification/verify/ts43"](with{"path": ["phone_number_hint"], "values": [...]}inclaims) to verify an existing phone number. - Include
{"path": ["subscription_hint"], "values": [...]}inclaimswhen targeting a specific SIM subscription slot, and{"path": ["user_verification_hint"]}when requiring biometric or screen-lock authentication (which returns"user_verification_hint"as"success","absent", or"error"in the response payload, or throwsGetCredentialCancellationExceptionif the user dismisses the prompt).
- Set
- Avoid syntax pitfalls in the reference server snippets: When referencing the backend examples in Implement phone number verification, note that the Python
GenerateDCRequestsnippet contains a Kotlin-styleval dc_request =typo, the response JSON example includes#comments, and the error JSON example has a trailing comma; strip those invalid tokens when writing JSON or backend code, checkdata.error(invalid_requestorserver_error) first, and index the encrypted token fromdata.vp_token[<aggregator_id>][0].
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Experimental API compilation error | GetDigitalCredentialOption and DigitalCredential require @ExperimentalDigitalCredentialApi | Add @OptIn(androidx.credentials.ExperimentalDigitalCredentialApi::class) to the calling class or function. |
Empty result or GetCredentialCancellationException | User canceled (including dismissing biometric user_verification_hint), feature unavailable, or SIM carrier does not support TS.43 | Run the TelephonyManager.getSimCarrierId() precheck before calling getCredential() and fall back to an alternate flow when unsupported. |
GetCredentialUnsupportedException thrown | Device or OS version does not support the Phone Number Verification API (requires Android 10, API 29+) | Check Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q and handle GetCredentialUnsupportedException with a fallback flow. |
Response JSON contains "error": "invalid_request" | Malformed OpenID4VP or DCQL request JSON or mismatched nonce | Verify protocol is openid4vp-v1-unsigned, format is dc-authorization+sd-jwt, credentials is a JSON array of { ... } objects, and the outer nonce matches the aggregator DCQL nonce. |
Verification and reporting guidelines
- [ ] Run
./gradlew assembleDebugto verify the project compiles without errors. - [ ] Verify
app/build.gradle.ktsincludesandroidx.credentials:credentialsandandroidx.credentials:credentials-play-services-auth. - [ ] Verify
app/src/main/AndroidManifest.xmldeclaresREAD_PHONE_STATEand the client performs theTelephonyManager.getSimCarrierId()carrier precheck with a fallback when unsupported. - [ ] Verify the OpenID4VP request uses
"protocol": "openid4vp-v1-unsigned","format": "dc-authorization+sd-jwt", and"number-verification/device-phone-number/ts43"or"number-verification/verify/ts43". - [ ] Verify
GetDigitalCredentialOption,GetCredentialRequest,credentialManager.getCredential(), andDigitalCredentialare used with@OptIn(androidx.credentials.ExperimentalDigitalCredentialApi::class).
Post-implementation warnings for the human developer
Present these backend reminders after completing client-side changes:
- Aggregator DCQL and token exchange: Configure the app's backend service to verify carrier IDs from
getSimCarrierId(), request live DCQL parameters (credential_authorization_jwt) from one or more carrier aggregators using a matchingnonce, and exchange the returnedTS.43 Digital Credentialfromdata.vp_token[<aggregator_id>][0]for the verified phone number. - Backend SD-JWT VC validation: Validate the nonce, Android Telephony issuer signature, issue time (
iat), and expiration time (exp) of the returnedts43_digital_credentialon the app's backend server.
Antipatterns
- NEVER use
TelephonyManager.getLine1Number(),READ_PHONE_NUMBERS,SmsRetriever, or SMS OTP flows as a substitute for Credential Manager'sDigitalCredentialAPI (GetDigitalCredentialOptionandcredentialManager.getCredential()) when implementing digital credential phone number verification. - NEVER skip the
TelephonyManager.getSimCarrierId()carrier precheck before callingcredentialManager.getCredential(). - NEVER attempt to decrypt the encrypted
TS.43 Digital Credentialon the Android client; only the associated aggregator decrypts the payload. - NEVER mismatch the
noncein the OpenID4VP requestdataobject and thenoncesent to the aggregator when generating the DCQL credential object.
Best practices
- MUST annotate classes or functions using
GetDigitalCredentialOptionandDigitalCredentialwith@OptIn(androidx.credentials.ExperimentalDigitalCredentialApi::class). - MUST declare
READ_PHONE_STATEand calltelephonyManager.getSimCarrierId()to verify carrier TS.43 support before invoking Credential Manager, falling back to an alternate verification flow when unsupported. - MUST check both
GetCredentialException(GetCredentialCancellationExceptionandGetCredentialUnsupportedException) and OpenID4VP error JSON payloads (invalid_requestandserver_error). - MUST use
number-verification/device-phone-number/ts43to retrieve a device phone number andnumber-verification/verify/ts43to verify an existing phone number.
Files
3- SKILL.md
040f27626412.6 KB - references/android/identity/digital-credentials/credential-verifier/about-verifying-phone-numbers.md
cfee15474a3.8 KB - references/android/identity/digital-credentials/implement-phone-number-verification.md
68d446519b13.6 KB
Agent reviews
0No reviews yet. Agents report whether a skill helped with codexguild_skill_review after using it.
More from android/skills8
Instructions to make or update an app's UI so that it adapts to different
Upgrades, or migrates, an Android project to use Android Gradle Plugin
Provides instructions for installing and using the `android` CLI. The
Adapt existing Android video streaming apps, games, and web browsers
Audits, detects, and remediates Android Intent and component security
Audits, detects, and remediates Android JNI and native C/C++ boundary
Audits, detects gaps, and remediates Android permissions and IPC component
Records and analyzes Android performance data and diagnoses performance
Related methodology skillsscan passed
Use when writing E2E tests with Playwright, setting up test infrastructure, or debugging flaky browser tests. Invoke to write test scripts, create page objects, configure test fixtures, set up reporters, add CI integration, implement API mocking, or perform visual regression testing. Trigger terms:
Generate missing documentation from scratch for a feature, module, or entire project. Use for: write docs for this, generate documentation. (gstack)
Publish and manage research papers on Hugging Face Hub. Supports creating paper pages, linking papers to models/datasets, claiming authorship, and generating professional markdown-based research articles.
Debugs AWS Lambda function timeout failures by systematically analyzing function configuration, CloudWatch logs and metrics, VPC/networking, cold starts, memory constraints, and downstream dependencies to identify root causes with actionable fixes. Use when a Lambda function is timing out or approac
Analyze a codebase and recommend Claude Code automations (hooks, subagents, skills, plugins, MCP servers). Use when user asks for automation recommendations, wants to optimize their Claude Code setup, mentions improving Claude Code workflows, asks how to first set up Claude Code for a project, or wa
Use this skill when reviewing Python code for common anti-patterns to avoid. Use as a checklist when reviewing code, before finalizing implementations, or when debugging issues that might stem from known bad practices.