Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -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 ->
Expand All @@ -127,6 +141,9 @@ class VerifierViewModel : ViewModel() {
MutableStateFlow<List<MobileCredentialPresentation>>(emptyList())
val receivedDocuments: StateFlow<List<MobileCredentialPresentation>> = _receivedDocuments

private val _sessionId = MutableStateFlow<String?>(null)
val sessionId: StateFlow<String?> = _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
Expand All @@ -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
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion ios-remote-verification-tutorial-sample-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading