Learn how to build an iOS application that can present an mDoc via an online workflow
Introduction
In this tutorial we will use the iOS native mDoc Holder SDK to build an iOS application that can present a claimed mDoc to a verifier remotely via an online presentation workflow as per ISO/IEC 18013-7:2024 and OID4VP.
This app will support both same-device and cross-device workflows to accommodate flexible user journeys.
Same-device workflow
- The user interacts with a website on their mobile device browser.
- The user is asked to present information as part of the interaction.
- The user is redirected to the application we will build in this tutorial.
- The application authenticates the user.
- The user is informed of what information they are about to share and provide their consent.
- The user is redirected back to the browser where verification results are displayed, enabling them to continue with the interaction.
The result will look something like this:
Cross-device workflow
- The user interacts with a website on their desktop browser.
- The user is asked to present information as part of the interaction.
- The user scans a QR code using a mobile device where the tutorial application is installed.
- The tutorial application is launched on the mobile device.
- The tutorial application authenticates the user.
- The user is informed of what information they are about to share and provide their consent.
- Verification results are displayed in the user’s desktop browser, enabling them to continue with the interaction.
The result will look something like this:
Prerequisites
Before we get started, let’s make sure you have everything you need.
Prior knowledge
-
The verification workflow described in this tutorial is based on ISO/IEC 18013-7:2024 and OID4VP. If you are unfamiliar with these technical specifications, refer to our Docs section for more information:
- What are mDocs?
- What is credential verification?
- Breakdown of the online presentation workflow.
-
We assume you have experience developing iOS native apps in Swift.
If you need to get a holding solution up and running quickly with minimal development resources and in-house domain expertise, talk to us about our white-label MATTR GO Hold app which might be a good fit for you.
Assets
- As part of your onboarding process you should have been provided with access to the following
assets:
- ZIP file which includes the required framework:
(
MobileCredentialHolderSDK-*version*.xcframework.zip
). - Sample Wallet app: You can use this app for reference as we work through this tutorial.
- ZIP file which includes the required framework:
(
This tutorial is only meant to be used with the most recent version of the iOS mDocs Holder SDK.
Development environment
- Xcode setup with either:
- Local build settings if you are developing locally.
- iOS developer account if you intend to publish your app.
Prerequisite tutorial
- You must complete the Claim a credential tutorial and claim the mDoc provided in the tutorial.
- This application is used as the base for the current tutorial.
Testing devices
- Supported iOS device to run the built application on, setup with:
- Biometric authentication (Face ID, Touch ID).
- Bluetooth access and Bluetooth turned on.
- Available internet connection.
Tutorial steps
To enable a user to present a stored mDoc to a verifier via an online presentation workflow, you will build the following capabilities into your application:
- Register the verifier’s Authorization endpoint.
- Create an online presentation session.
- Handle a presentation request.
- Send a presentation response.
Register the verifier’s Authorization endpoint
The Authorization endpoint is a URI associated with an application identifier in the MATTR VII tenant configuration. It is used to invoke an application that will handle the presentation request. The application then uses the URI to retrieve a request object, which details what information is required for verification.
Online verifiers are recommended to generate this URI as a Universal link, as this enables them to explicitly define and validate applications that can respond to their verification requests.
However, for simplicity reasons in this tutorial our verifier is using the default
custom URI scheme
defined by the OID4VP specification (mdoc-openid4vp
). This means that we need to configure the
application to be able to handle this custom URI scheme.
- Open the Xcode project with the application built in the Claim a credential tutorial.
- Register
mdoc-openid4vp
as a recognized URL scheme:- Open the project view and select your application target.
- Select the Info tab.
- Scroll down and expand the URL Types area.
- Select the plus button.
- Insert
mdoc-openid4vp
in both the Identifier and URL Schemes fields.
-
Run the app and then close it (this updates the app on your testing device) and perform the following instructions:
- Use a desktop browser to navigate to the MATTR Labs Maggie’s Groceries demo, where you must provide proof for purchasing an age restricted item.
- In the checkout area, use the dropdown list to select Generic Wallet.
- Select Share from wallet.
- Open the camera on your testing mobile device and scan the QR code.
- Confirm opening the QR code with your tutorial application.
- The tutorial application should be launched on your testing mobile device.
Create an online presentation session
Now that the application can handle an OID4VP custom URI scheme, the next step is build the capability to use the request URI to retrieve the request object, which includes the following information:
- What credentials are required.
- What specific claims are required from these credentials.
- What MATTR VII tenant to interact with.
-
In your project’s
ContentView
file, add the following code under the// Online Presentation - Step 2.1: Create a variable to hold the online presentation session object
comment to create a variable that will hold the online presentation session object.Swift@Published var onlinePresentationSession: OnlinePresentationSession?
-
Add the following code under the
// Online Presentation - Step 2.2: Create createOnlinePresentationSession function
to create a function that uses the SDK’screateOnlinePresentationSession
method with theauthorizationRequestURI
parameter (the request URI retrieved from the link/QR code) to create anOnlinePresentationSession
instance and assign it to theonlinePresentationSession
variable created in the previous step:Swiftfunc createOnlinePresentationSession(authorizationRequestURI: String) async { Task { @MainActor in do { onlinePresentationSession = try await mobileCredentialHolder.createOnlinePresentationSession(authorisationRequestUri: authorizationRequestURI, requireTrustedVerifier: false) } catch { print(error.localizedDescription) } } }
We chose to set requireTrustedVerifier
parameter to false
because we want the SDK to trust
all verifiers by default. If you require to interact with a limited list of verifiers, you may
want to manually add trusted verifier certificates and set the parameter to true
. You can
learn more about certificate management in our SDK
docs.
-
Add the following code under the
// Online Presentation - Step 2.3: Create session from request URI
comment to add an onOpenURL modifier that will call thecreateOnlinePresentationSession
when the application is launched following selecting a link (same-device flow) or scanning a QR code (cross-device flow) that includes a registered URI:Swift.onOpenURL { url in Task { await viewModel.createOnlinePresentationSession(authorizationRequestURI: url.absoluteString) } // Online Presentation - Step 3.6: Launch online presentation session view automatically }
Handle a presentation request
We will now build the capability to use information retrieved by the
createOnlinePresentationSession
function to handle the presentation request. This includes:
- Displaying what information is requested.
- Displaying what existing credentials match the request.
- Getting user’s consent to sharing the information.
- Add the following code under the
// Online Presentation - Step 3.1: Create variable to store selected credential
comment to create a variable that will store the credential the user will select to share with the verifier:
@State var selectedCredential: String?
- Add the following code under the
// Online Presentation - Step 3.2: Create PresentCredentialsView
comment to add a new view that will be used for displaying matched credentials and enabling the user to select a credential to share with the verifier:
var onlinePresentationSessionView: some View {
VStack {
if viewModel.onlinePresentationSession?.matchedCredentials != nil {
List(selection: $selectedCredential) {
Section(header: Text("Requested Document")) {
Text("\(viewModel.onlinePresentationSession!.matchedCredentials![0].request.docType)")
}
let matchedCredentials = viewModel.onlinePresentationSession!.matchedCredentials![0].matchedMobileCredentials
Section(header: Text("Please select matching document to present")) {
ForEach(matchedCredentials, id: \.id) { credential in
Text(credential.docType)
}
}
}
if let selectedCredential {
Button {
// Online Presentation Step 4.2: Call sendResponse function
} label: {
Text("Send Response")
}
}
}
Spacer()
}
}
- Add the following code under the
// Online Presentation - Step 3.3: Add isPresentingOnlinePresentation variable
comment to manage navigation to theonlinePresentationSessionView
view:
@State var isPresentingOnlinePresentation = false
- Add the following code under the
// Online Presentation - Step 3.4: View Online Presentation Session
comment to add add a new button that will enable the user to manually navigate to theonlinePresentationSessionView
view if required:
if viewModel.onlinePresentationSession != nil {
Button("View Online Presentation Session") {
isPresentingOnlinePresentation = true
}
.padding()
}
- Add the following code under the
// Online Presentation - Step 3.5: Add navigation to onlinePresentationSessionView
comment to control navigation to theonlinePresentationSessionView
view:
.navigationDestination(isPresented: $isPresentingOnlinePresentation) {
onlinePresentationSessionView
}
- Add the following code under the
// Online Presentation - Step 3.6: Launch online presentation session view automatically
comment to automatically launch theonlinePresentationSessionView
view when the user interacts with an online credential request:
isPresentingOnlinePresentation = true
-
Run the app and then close it (this updates the app on your testing device) and perform the following instructions:
- Use a desktop browser to navigate to the MATTR Labs Maggie’s Groceries demo, where you must provide proof for purchasing an age restricted item.
- In the checkout area, use the dropdown list to select Generic Wallet.
- Select Share from wallet.
- Open the camera on your testing mobile device and scan the QR code.
- Confirm opening the QR code with your tutorial application.
- The tutorial application should be launched on your testing mobile device, displaying the verification request and any matching credentials.
The result will look something like this:
Send response
After displaying matching credentials to the user and enabling them to select what credential to share, the last thing we need to do is build the capability to share the selected credential with the verifier.
- Add the following code under the
// Online Presentation - Step 4.1: Create send response function
comment to create a new function that will call the SDK’ssendResponse
method of theonlinePresentationSession
object and send the selected credential to the verifier:
func sendOnlinePresentationSessionResponse(_ id: String) {
Task { @MainActor in
do {
_ = try await onlinePresentationSession?.sendResponse(credentialIds: [id])
} catch {
print(error)
}
}
}
- Add the following code after the
// Online Presentation - Step 4.2: Call sendResponse function
so that the sendResponse function is called when the user selects the Send Response button.
viewModel.sendOnlinePresentationSessionResponse(selectedCredential)
isPresentingOnlinePresentation = false
Test the application
Let’s test that the application is working as expected in both workflows.
Same-device workflow
- Run the app and then close it (this updates the app on your testing device).
- Use a browser on your testing mobile device to navigate to the MATTR Labs Maggie’s Groceries demo, where you must provide proof for purchasing an age restricted item.
- In the checkout area, use the dropdown list to select Generic Wallet.
- Select Share from wallet.
- Select Allow to open the tutorial application.
- The tutorial application should be launched on your testing mobile device.
- Select the credential you wish to send to the verifier from the list of matched credentials.
- Select Send Response.
- You should be redirected back to Maggie’s online store and see a Over 18 years old verified indication.
- You can now proceed with the interaction (don’t expect any items to be shipped to you by Maggie’s though).
The result will look something like this:
Cross-device workflow
- Run the app and then close it (this updates the app on your testing device).
- Use a desktop browser to navigate to the MATTR Labs Maggie’s Groceries demo, where you must provide proof for purchasing an age restricted item.
- In the checkout area, use the dropdown list to select Generic Wallet.
- Select Share from wallet.
- Open the camera on your testing mobile device and scan the QR code.
- Confirm opening the QR code with your tutorial application.
- The tutorial application should be launched on your testing mobile device.
- Select the credential you wish to send to the verifier from the list of matched credentials.
- Select Send Response.
- Back on your desktop browser, you should see a Over 18 years old verified indication.
- You can proceed with the interaction (don’t expect any items to be shipped to you by Maggie’s though).
The result will look something like this:
Summary
You have just used the iOS native mDoc Holder SDK to build an iOS application that can present a claimed mDoc to a verifier remotely via an online presentation workflow as per ISO/IEC 18013-7:2024 and OID4VP.
This was achieved by building the following capabilities into the application:
- Handle an OID4VP request URI.
- Create an online presentation session.
- Handle a presentation request.
- Send a presentation response.
What’s next?
- You can check out the iOS mDoc holder SDK Docs to learn more about available functions and classes.