A framework that provides a secured and simplified data-sharing process from Affinidi Vault with user consent for enhanced user experience. The Affinidi Iota Framework leverages the OID4VP (OpenID for Verifiable Presentation) standard to request and receive data from Affinidi Vault. The OID4VP is built with the OAuth 2.0 authorisation framework, providing developers with a simple and secure presentation of credentials.
More Details on Affinidi Iota Framework is available on Affinidi Documentation
We will use the same Eventi App
which we worked on in modules 1 & module 2 and enable the Affinidi Iota framework for requesting music preferences and show the personalised experience for events happening. It implements workflows that ensure users have full control over their data, emphasizing secure and transparent data-sharing practices using OID4VP & PEX.
S.No | Content | Description |
---|---|---|
1. | Pre-Requisite | Complete the pre-requisite for Affinidi Iota Framework |
2. | Add Recommendations PEX | Update Affinidi Iota Framework to request music preferences |
3. | Update .env files | Update .env files |
4. | Use useIotaQuery React Custom Hook | Initiate Iota Request using react custom hook |
5. | Invoke Request on Event handler | Invoke Iota initiation request inside the handleInitiateRecommendations() |
6. | Run Application | Try the App with Affinidi Login & Affinidi Iota Framework |
Important
This Module is an extension of the same Eventi App that we worked on for Module 1.
If you have completed Module 3 go to next step, otherwise would require to complete the steps listed below.
- Iota Configuration should be created as mentioned in Module 3
- Install Dependencies as mentioned in Module 3
- Create API to initiate Iota request
- Create API to get data from the Iota Initiate request
Now, let's continue with the step-by-step guide to enable the Affinidi Iota framework in the sample App by adding Recommendations PEX in Affinidi Iota Configuration.
Add New Presentation Definition for requesting music preferences in Affinidi Iota framework configuration by using the Affinidi Portal
-
Login to Affinidi Portal
-
Open Your Iota Configuration details by clicking on
Affinidi Iota Framework
menu underFrameworks
section -
If Iota Configuration Data sharing flow mode is
Redirect
then Edit the Iota configuration details and add anotherRedirect URLs
with new line ashttp://localhost:3000/
and then ClickSave
button -
Click
Edit
button underCreate Presentation Definitions
section to add new presentation definition for requesting music recommendations -
Click
+ Add
button and providing the name of the Presentation Definition asMusic Recommendations
and then select from the available templates to pre-populate the editor and modify with the below presentation definition to requestMusic Recommendations Credential
from the Affinidi Vault.
{
"id": "music",
"input_descriptors": [
{
"id": "category_vc",
"name": "Category VC",
"purpose": "Get some category data",
"constraints": {
"fields": [
{
"path": [
"$.@context"
],
"purpose": "Verify VC Context",
"filter": {
"type": "array",
"contains": {
"type": "string",
"pattern": "^https://schema.affinidi.io/profile-template/context.jsonld$"
}
}
},
{
"path": [
"$.type"
],
"purpose": "Verify VC Type",
"filter": {
"type": "array",
"contains": {
"type": "string",
"pattern": "^ProfileTemplate$"
}
}
},
{
"path": [
"$.credentialSubject.categories.music.favoriteGenres[0].favoriteGenre"
]
},
{
"path": [
"$.credentialSubject.categories.behaviors.interests[0].interest"
]
}
]
}
}
]
}
- Click on
Create
button,QueryId
for requesting Event Ticket VC is generated.
Update .env
file with the ConfigurationId
and QueryId
obtained in previous step
NEXT_PUBLIC_IOTA_CONFIG_ID=""
NEXT_PUBLIC_IOTA_MUSIC_RECOMMEND_QUERY=""
Use React Custom Hook useIotaQuery
to Request Event Ticket VC
Open the Landing Page component src\components\LandingPage\index.tsx
which displays list of events, and add the below code snippet which uses react custom hook to initiate the Affinidi Iota Request.
//Start of Iota Request
const { handleInitiate, data: iotaRequestData } = useIotaQuery({
configurationId: iotaConfigId,
});
useEffect(() => {
if (!iotaRequestData) return;
//data for recommendations
const musicData = iotaRequestData[recommendationIota];
if (musicData) {
const obj = "" + localStorage.getItem("consumerCurrentState");
let userUpd: ConsumerInfoProps = JSON.parse(obj);
const usernew = {
...userUpd?.user,
interest: musicData.categories?.behaviors.interests[0].interest,
genre: musicData.categories?.music.favoriteGenres[0].favoriteGenre,
};
filterProducts(usernew.genre);
storeConsumerInfo((prev) => ({ ...prev, user: usernew }));
setHasItem(true);
}
}, [iotaRequestData]);
//EOD of Iota Request
Apply Action on Button Click handleInitiateRecommendations
handler
Invoke handleInitiate
function on click on the share ticket button handler handleInitiateRecommendations
//Event Handler
const handleInitiateRecommendations = () => {
//Initiate Affinidi Iota request
handleInitiate(recommendationIota);
};
Run The application to experience the Affinidi Iota framework.
Try the App with Affinidi Iota Framework and click on Give Me Recommendations
button on the landing page.
Note
The Eventi App filters events exclusively by music genres such as Pop
, Rock
, Hip Hop
, and Jazz
. Try giving one of these values in your Affinidi vault to view the filtered events based on the chosen genre.
npm run dev
Open http://localhost:3000/ with your browser to see the result.