Credential Verifier
يطلب ويتحقق من الهويات الرقمية مثل رخص القيادة الرقمية من تطبيق Android.
Request and verify digital credentials (such as ISO mdoc mobile driver's licenses and SD-JWT credentials) from a holder wallet in an Android app or WebView using Jetpack Credential Manager. Use this skill when building a digital credential verifier app in an Android project, constructing OpenID4VP (openid4vp-v1-unsigned) and Digital Credential Query Language (dcql_query) requests, calling CredentialManager.getCredential with GetDigitalCredentialOption, requesting multiple credentials simultaneou
Install
npx skills add android/skills --skill credential-verifierWorks with
claude-code (native), claude (native), codex (native), chatgpt (native), gemini-cli (native), cursor (native), copilot (native), opencode (native), amp (native), roo (native), kiro (native), goose (native), junie (native), trae (native), cline (compatible), continue (compatible), antigravity (compatible), windsurf (compatible), augment (compatible), qwen-code (compatible)
Content
Build an Android verifier (relying party) app that requests and verifies digital credentials (mso_mdoc and dc+sd-jwt) from a user's holder wallet over OpenID4VP (openid4vp-v1-unsigned) and Digital Credential Query Language (dcql_query) using GetDigitalCredentialOption and credentialManager.getCredential(), either directly in an Android app or through a WebView JavaScript bridge. When reviewing digital credential architecture, trust requirements, or verifier implementation snippets, consult [Digital credentials overview](references/android/identity/digital-credentials/index.md), [About trust and safety](references/android/identity/digital-credentials/trust-safety.md), [Request credentials](references/android/identity/digital-credentials/credential-verifier/request-credential.md), and [Request a credential through WebView](references/android/identity/digital-credentials/credential-verifier/webview-request.md). When building a wallet app that stores and presents credentials, suggest the credential-holder skill; when issuing credentials to a wallet, suggest the credential-issuer skill; when implementing carrier TS.43 phone number verification, suggest the phone-number-verification skill.
Prerequisites and setup
- Android version compatibility: Runtime support for the Verifier API requires Android 9 (API level 28) and higher (
WebViewJavaScript bridge targets API level 23 or higher, andandroidx.credentialscompiles withminSdk23 or higher). - 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 (and
androidx.webkitwhen bridgingWebViewrequests) to the app module build script (app/build.gradle.ktsorapp/build.gradle; when checking full dependency snippets, consult [Request credentials](references/android/identity/digital-credentials/credential-verifier/request-credential.md) and [Request a credential through WebView](references/android/identity/digital-credentials/credential-verifier/webview-request.md)):
| Scenario | Artifact | Key classes, constructor signatures, and package | |---|---|---| | All verifier flows | 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, NoCredentialException, GetCredentialUnknownException, and GetCredentialCustomException in androidx.credentials.exceptions | | All verifier flows | androidx.credentials:credentials-play-services-auth:1.7.0-alpha03 (or 1.6.0+) | Google Play services provider integration for Credential Manager | | WebView bridge | androidx.webkit:webkit:1.18.0 | WebViewCompat, WebViewCompat.WebMessageListener, WebMessageCompat, WebViewFeature, and JavaScriptReplyProxy in androidx.webkit |
Expected inputs and file scope
- Required inputs: The credential formats (
mso_mdocwithdoctype_valueordc+sd-jwtwithvct_values) and minimum selective-disclosure claims to request, and whether verification runs directly in an Android screen or inside aWebView. - Files to modify:
app/build.gradle.kts, verifier client or repository classes,WebViewCompat.WebMessageListenerbridge classes (when usingWebView), ViewModels, and UI screens (such asMainActivity.kt).
Codebase exploration
Before modifying files, inspect the Android project:
- Validate baseline build and inspect configuration: Run
./gradlew assembleDebugto confirm the project compiles before making changes, and checkapp/build.gradle.ktsandgradle/libs.versions.tomlforminSdk,androidx.credentials, andandroidx.webkitdependencies. - Locate target UI entry points: Identify the
Activityor Compose screen (such asMainActivity.ktorTasksScreen.kt) where verification is triggered socredentialManager.getCredential()receives anActivityContext.
Critical implementation mandates
- Opt in to experimental APIs: Annotate classes or functions referencing
GetDigitalCredentialOptionorDigitalCredentialwith@OptIn(androidx.credentials.ExperimentalDigitalCredentialApi::class)(omitted from the snippet in [Request credentials](references/android/identity/digital-credentials/credential-verifier/request-credential.md)). - Use the exact OpenID4VP and DCQL JSON schema: Follow the single-credential (
mso_mdocordc+sd-jwt) and multi-credential (dcql_query.credentials) JSON schemas in [Request credentials](references/android/identity/digital-credentials/credential-verifier/request-credential.md) ("protocol": "openid4vp-v1-unsigned","response_type": "vp_token","response_mode": "dc_api","nonce", and"dcql_query"). Never wrap the AndroidGetDigitalCredentialOption(requestJson)payload in a browser-only{"providers": [...]}object. - Send
credentialJsonto the app's backend for verification: Extractcredential.credentialJsonfromDigitalCredentialand send it with the sessionnonceto the app's backend to verify the cryptographic signature and issuer trust chain; never trust unverified claims directly on the client. - Complete the
WebViewlistener andAndroidViewsetup: When following [Request a credential through WebView](references/android/identity/digital-credentials/credential-verifier/webview-request.md): - Add
androidx.webkit:webkit:1.18.0alongside the Credential Manager dependencies and inject thebridge.jsscript that interceptsnavigator.credentials.get({ digital }). - Implement
WebViewCompat.WebMessageListener.onPostMessage(view: WebView, message: WebMessageCompat, sourceOrigin: Uri, isMainFrame: Boolean, replyProxy: JavaScriptReplyProxy)(described in prose only in [Request a credential through WebView](references/android/identity/digital-credentials/credential-verifier/webview-request.md)): verifyisMainFrameistrueandsourceOrigin.scheme == "https", parsemessage.data, callcredentialManager.getCredentialwithGetDigitalCredentialOption, and returncredential.credentialJson(or a JSON error object) throughreplyProxy.postMessage(...). - Inside
WebView(context).apply { ... }inAndroidView, passthis(not an undeclaredwebViewvariable) toWebViewCompat.addWebMessageListener, pass the declaredhandlervariable toDigitalCredentialWebListener, and close theif (WebViewFeature.isFeatureSupported(...))block before callingloadUrl("https://...").
Troubleshooting
| Symptom | Cause | Fix | |---|---|---| | Experimental API compilation error | GetDigitalCredentialOption and DigitalCredential require opt-in | Add @OptIn(androidx.credentials.ExperimentalDigitalCredentialApi::class) to the calling class or function. | | Compilation error on CreateCredentialUnknownException in when (e: GetCredentialException) | CreateCredential*Exception doesn't inherit from GetCredentialException | Match GetCredentialUnknownException and GetCredentialCustomException instead. | | Credential selector fails or returns invalid request | Using a browser providers wrapper object instead of OpenID4VP | Use "requests" with "protocol": "openid4vp-v1-unsigned", "response_type": "vp_token", "response_mode": "dc_api", and "dcql_query". | | WebView credential request fails silently | WebMessageListener not registered or origin not allowed | Check WebViewFeature.WEB_MESSAGE_LISTENER and register WebViewCompat.addWebMessageListener with explicit HTTPS allowedOriginRules before loadUrl. |
Verification and reporting guidelines
- \[ \] Run
./gradlew assembleDebugto verify the Android project compiles without errors. - \[ \] Verify
app/build.gradle.ktsincludesandroidx.credentials:credentialsandandroidx.credentials:credentials-play-services-auth(plusandroidx.webkit:webkitforWebViewflows). - \[ \] Verify the OpenID4VP request JSON uses
"protocol": "openid4vp-v1-unsigned","response_type": "vp_token","response_mode": "dc_api", and"dcql_query". - \[ \] Verify
credentialManager.getCredential()is called with anActivityContextand catchesGetCredentialExceptionsubtypes.
Post-implementation warnings for the human developer
Present these reminders after completing verifier code changes:
- Server-side cryptographic verification: Generate single-use cryptographic
noncevalues on the app's backend and verify the returnedDigitalCredential.credentialJson(vp_tokenissuer signature, trust chain, device binding, and nonce) on the backend server before trusting any claims. - Minimum selective disclosure: Request only the minimum attributes needed (such as
age_over_21rather than full birth date or address) indcql_query.
Antipatterns
- NEVER implement a digital credential verifier using only a simulated QR scanner or local mock UI without integrating
CredentialManagerandGetDigitalCredentialOption. - NEVER invent a top-level
{"providers": [...]}JSON schema forGetDigitalCredentialOption(requestJson)in an Android verifier app; always use"requests"with"protocol": "openid4vp-v1-unsigned"and"dcql_query". - NEVER trust raw claims parsed on the client without validating
credential.credentialJsonand the sessionnonceon the app's backend.
Best practices
- MUST annotate classes or functions using
GetDigitalCredentialOptionandDigitalCredentialwith@OptIn(androidx.credentials.ExperimentalDigitalCredentialApi::class). - MUST handle
GetCredentialCancellationException,GetCredentialInterruptedException,NoCredentialException,GetCredentialUnknownException, andGetCredentialCustomExceptionwhen callingcredentialManager.getCredential(). - MUST verify
isMainFrameandhttpssourceOrigininWebViewWebMessageListener.onPostMessagebefore forwarding credential requests toCredentialManager.
Source and license
- Source
- Android Skills
- Original
- android/skills/identity/digital-credentials/credential-verifier/SKILL.md
- License
- Apache-2.0