From afd4d7787efc29847df4206fcd92564a96ec0fda Mon Sep 17 00:00:00 2001 From: Avner Matan <137777701+avner-m@users.noreply.github.com> Date: Mon, 9 Nov 2026 11:41:07 +1300 Subject: [PATCH] fix(remote-verification): show the session ID when results are delivered to the backend Co-Authored-By: Claude Opus 5.5 --- .../README.md | 2 +- .../mobileverifiertutorial/MainActivity.kt | 30 +++++++++++++++++-- .../README.md | 2 +- .../ContentView.swift | 28 +++++++++++++++-- .../App.tsx | 11 +++++-- 5 files changed, 63 insertions(+), 10 deletions(-) diff --git a/android-remote-verification-tutorial-sample-app/README.md b/android-remote-verification-tutorial-sample-app/README.md index f75413ae..5618721a 100644 --- a/android-remote-verification-tutorial-sample-app/README.md +++ b/android-remote-verification-tutorial-sample-app/README.md @@ -10,7 +10,7 @@ This project accompanies the [Remote mobile verifiers tutorial](https://learn.ma 1. Shows a **Request credentials** button that builds a presentation request for an mDL (`org.iso.18013.5.1.mDL`) and asks for the `family_name`, `given_name`, and `birth_date` claims. 2. Hands off to a compliant wallet app on the device, where the holder consents to share the requested claims. -3. Receives the verification result back via the OID4VP deep link declared in `AndroidManifest.xml` and renders the verified claims, the overall verification status, and any claim errors. +3. Receives the wallet's redirect back via the OID4VP deep link declared in `AndroidManifest.xml` and displays the session ID. With a custom URL scheme redirect, your backend retrieves the verification results for that session from your MATTR VII tenant. When the results are returned to the app, it renders the verified claims, the overall verification status, and any claim errors. ## Prerequisites diff --git a/android-remote-verification-tutorial-sample-app/app/src/main/java/com/example/mobileverifiertutorial/MainActivity.kt b/android-remote-verification-tutorial-sample-app/app/src/main/java/com/example/mobileverifiertutorial/MainActivity.kt index 12ea0aec..4d472e63 100644 --- a/android-remote-verification-tutorial-sample-app/app/src/main/java/com/example/mobileverifiertutorial/MainActivity.kt +++ b/android-remote-verification-tutorial-sample-app/app/src/main/java/com/example/mobileverifiertutorial/MainActivity.kt @@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.material3.Button import androidx.compose.material3.Scaffold import androidx.compose.material3.Text @@ -22,6 +23,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp import androidx.lifecycle.ViewModel import androidx.lifecycle.lifecycleScope import androidx.lifecycle.viewModelScope @@ -91,6 +93,7 @@ fun Content(modifier: Modifier = Modifier) { val viewModel: VerifierViewModel = viewModel() val documents by viewModel.receivedDocuments.collectAsState() + val sessionId by viewModel.sessionId.collectAsState() Column( modifier = modifier.fillMaxSize(), @@ -102,6 +105,17 @@ fun Content(modifier: Modifier = Modifier) { }) { Text("Request credentials") } + // When the tenant returns the session ID without the verification results, your backend + // retrieves the results for this session from your MATTR VII tenant. + sessionId?.let { id -> + Text( + "Retrieve the verification results from your backend with this session ID:", + modifier = Modifier.padding(16.dp) + ) + SelectionContainer { + Text(id) + } + } // Step 4.5: Render any received documents. LazyColumn(modifier = Modifier.fillMaxWidth()) { items(documents) { document -> @@ -127,6 +141,9 @@ class VerifierViewModel : ViewModel() { MutableStateFlow>(emptyList()) val receivedDocuments: StateFlow> = _receivedDocuments + private val _sessionId = MutableStateFlow(null) + val sessionId: StateFlow = _sessionId + fun requestCredentials(activity: Activity) { // Step 3.1: Build the MobileCredentialRequest. docType selects the credential type // and namespaces declares which claims to request. Each claim's boolean flag @@ -145,6 +162,7 @@ class VerifierViewModel : ViewModel() { viewModelScope.launch { _receivedDocuments.value = emptyList() + _sessionId.value = null try { // Step 3.2: Request credentials. The SDK launches the wallet via OID4VP and // suspends until the wallet redirects back via the deep link registered in @@ -159,8 +177,16 @@ class VerifierViewModel : ViewModel() { // Step 4.2: Surface the verified credentials to the UI. From v7.0.0, // OnlinePresentationSessionResult is a sealed interface with Success/Failure variants. _receivedDocuments.value = when (onlinePresentationResult) { - is OnlinePresentationSessionResult.Success -> - onlinePresentationResult.mobileCredentialResponse?.credentials ?: emptyList() + is OnlinePresentationSessionResult.Success -> { + val response = onlinePresentationResult.mobileCredentialResponse + // mobileCredentialResponse is null when the tenant delivers the results to + // your backend, for example when the redirect URI uses a custom URL scheme. + // Keep the session ID so your backend can retrieve the results. + if (response == null) { + _sessionId.value = onlinePresentationResult.sessionId + } + response?.credentials ?: emptyList() + } is OnlinePresentationSessionResult.Failure -> { // onlinePresentationResult.error is available here. emptyList() diff --git a/ios-remote-verification-tutorial-sample-app/README.md b/ios-remote-verification-tutorial-sample-app/README.md index 0c9bf72b..ad010c8f 100644 --- a/ios-remote-verification-tutorial-sample-app/README.md +++ b/ios-remote-verification-tutorial-sample-app/README.md @@ -10,7 +10,7 @@ This project accompanies the [Remote mobile verifiers tutorial](https://learn.ma 1. Shows a **Request credentials** button that builds a presentation request for an mDL (`org.iso.18013.5.1.mDL`) and asks for the `family_name`, `given_name`, and `birth_date` claims. 2. Redirects to a compliant wallet app on the device, where the holder consents to share the requested claims. -3. Receives the verification result back via a deep link (a custom URL scheme) and displays the verified claims, the overall verification status, and any claim errors. +3. Receives the wallet's redirect back via a deep link (a custom URL scheme) and displays the session ID. With a custom URL scheme redirect, your backend retrieves the verification results for that session from your MATTR VII tenant. When the results are returned to the app, it displays the verified claims, the overall verification status, and any claim errors. ## Prerequisites diff --git a/ios-remote-verification-tutorial-sample-app/Remote verification tutorial/ContentView.swift b/ios-remote-verification-tutorial-sample-app/Remote verification tutorial/ContentView.swift index 6249e641..f40af819 100644 --- a/ios-remote-verification-tutorial-sample-app/Remote verification tutorial/ContentView.swift +++ b/ios-remote-verification-tutorial-sample-app/Remote verification tutorial/ContentView.swift @@ -40,7 +40,20 @@ struct ContentView: View { var presentationResponseView: some View { ZStack { - if viewModel.receivedDocuments.isEmpty { + if let sessionId = viewModel.sessionId { + // The tenant returned the session ID without the verification results. Your backend + // retrieves the results for this session from your MATTR VII tenant. + VStack(spacing: 20) { + Text("Presentation complete") + .font(.title) + Text("Retrieve the verification results from your backend with this session ID:") + .multilineTextAlignment(.center) + Text(sessionId) + .font(.system(.body, design: .monospaced)) + .textSelection(.enabled) + } + .padding() + } else if viewModel.receivedDocuments.isEmpty { VStack(spacing: 40) { Text("Waiting for response...") .font(.title) @@ -67,6 +80,7 @@ struct ContentView: View { final class VerifierViewModel: ObservableObject { @Published var navigationPath = NavigationPath() @Published var receivedDocuments: [MobileCredentialPresentation] = [] + @Published var sessionId: String? // From v6.0.0, the applicationId is supplied via PlatformConfiguration (it is no longer passed // to requestMobileCredentials) and also drives SDK Tethering. @@ -122,6 +136,7 @@ final class VerifierViewModel: ObservableObject { func requestCredentials() { Task { @MainActor in receivedDocuments = [] + sessionId = nil do { // From v6.0.0, applicationId is no longer passed here (it comes from // PlatformConfiguration) and challenge is optional — omit it to let the SDK generate @@ -135,8 +150,15 @@ final class VerifierViewModel: ObservableObject { // fields. success carries (sessionId, challenge, mobileCredentialResponse); failure // carries (sessionId, challenge, error). switch onlinePresentationResult { - case .success(_, _, let mobileCredentialResponse): - receivedDocuments = mobileCredentialResponse?.credentials ?? [] + case .success(let sessionId, _, let mobileCredentialResponse): + // mobileCredentialResponse is nil when the tenant delivers the results to your + // backend, for example when the redirect URI uses a custom URL scheme. Keep the + // session ID so your backend can retrieve the results. + guard let mobileCredentialResponse else { + self.sessionId = sessionId + return + } + receivedDocuments = mobileCredentialResponse.credentials case .failure(_, _, let error): print("No response received: \(error.message)") return diff --git a/react-native-remote-verification-tutorial/react-native-remote-verification-tutorial-complete/App.tsx b/react-native-remote-verification-tutorial/react-native-remote-verification-tutorial-complete/App.tsx index 5aae9002..25c0230c 100644 --- a/react-native-remote-verification-tutorial/react-native-remote-verification-tutorial-complete/App.tsx +++ b/react-native-remote-verification-tutorial/react-native-remote-verification-tutorial-complete/App.tsx @@ -151,11 +151,16 @@ export default function App() { throw new Error(`Verification session failed: ${session.error.message}`); } - // `mobileCredentialResponse` is absent when the verifier application is configured to deliver - // results over the back channel only, so the credentials never reach this app. + // `mobileCredentialResponse` is absent when the tenant delivers the results to your backend, + // for example when the redirect URI uses a custom URL scheme. Your backend retrieves the results + // for this session from your MATTR VII tenant using the session ID. const response = session.mobileCredentialResponse; if (!response) { - throw new Error("No verification results were returned by the tenant."); + Alert.alert( + "Presentation complete", + `Retrieve the verification results from your backend with this session ID:\n\n${session.sessionId}` + ); + return; } // Store the verification results and display them to the verifier app user.