Getting the Verifiable Credentials .NET sample 3 working (Part 1)

Rory Braybrook
The new control plane
4 min readJun 5, 2023
Image showing a B2C VC

If you haven’t read the first article, have a read here.

Setup the basic VC stuff as per that article.

The Github sample is here.

There are three .NET samples there. The above link refers to the first sample.

This post is about the third sample.

There are two parts to the sample.

  • Part 1 is about getting the website working. This includes the VC API’s for issue and verify.
  • Part 2 is about setting up the custom policies to use those API’s.

The ngrok command to get this working is:

ngrok http https://localhost:5001

The key to getting this sample working are the rules and display files (gist here) and the appsettings.json file.

Note the type in the rules file:

"type": [
"B2CVerifiedAccount"
]

The appsettings are:

{
"Logging": {
"LogLevel": {
"Default": "Trace",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"AppSettings": {
"ApiEndpoint": "https://verifiedid.did.msidentity.com/v1.0/verifiableCredentials/",
"Authority": "https://login.microsoftonline.com/{0}",
"scope": "3db474b9-6a0c-4840-96ac-1fceb342124f/.default",
"TenantId": "00d...c79",
"ClientId": "6d4...838",
"ClientSecret": "hnL...bR0",
"ApiKey": "B2C_1A_VCRestApiKey",
"CookieKey": "state",
"CookieExpiresInSeconds": 7200,
"CacheExpiresInSeconds": 300,
"client_name": "DotNet B2C+VC sample",
"Purpose": "To prove your identity",
"VerifierAuthority": "did:ion:EiC...ZyJ9fQ",
"IssuerAuthority": "did:ion:EiC...ZyJ9fQ",
"CredentialType": "B2CVerifiedAccount",
"DidManifest": "https://verifiedid.did.msidentity.com/v1.0/tenants/00d...c79/verifiableCredentials/contracts/4e0...bb/manifest",
"IssuancePinCodeLength": 0,
"B2C1ARestApiKey": ""

}
}

Note how the “CredentialType” in the appsettings matches the value in the rules file. This is how you control what VC are acceptable.

Using the rules and display files, create a new custom credential in the Azure AD Verified ID tab by copy/pasting the files.

Call the credential something like “B2C Verified Credential”.

It should look like:

Image showing credtial preview with type, claims and manifest

If you click on the “4 claims” link, you see:

Image showing the four claims i.e. “oid”, “tid”, “firstName” and “lastName”

that match the claims in the rules file.

Copy the “Manifest URL” and paste it in “DidManifest” in the settings.

Run the sample and navigate to the ngrok link in the browser.

e.g. for:

Forwarding https://ecb3-122-60-191-57.ngrok-free.app -> https://localhost:5001 

Use:

https://ecb3–122–60-191-57.ngrok-free.app

You should see:

Image showing “Issue Credential” button

Click “Issue Credential”.

Image showing oid, tid, first name and last name filled in and “Issue Credential” button

This sample is actually designed to work with a B2C custom policy which we will use in part 2.

However, you have to get this sample working first as it underlies the custom policy one.

Hence, you need to enter the above attributes (which can be any value) as these would normally be derived from the custom policy sign up / sign in process.

Click “Issue Credential”.

Image showing QR code

Scan the QR code with the Authenticator app.

Image showing the Authenticator app. with new VC showing and “Add” button

Click “Add”.

The verified ID should be accepted.

Image showing “issuance process is completed”

If we look at the details of the VC:

Image showing Authenticator app. with VC details of first name and last name.

we can see the attributes match those that we typed in above.

Navigate back to:

https://ecb3-122-60-191-57.ngrok-free.app/

Click “Verify Credential”.

Image showing “Prove Credentail” button

Click “Prove Credential”.

Image showing QR code

Scan the QR code with the Authenticator app.

Image showing Authenticator app. with list of suitable VC and “Share” button

Click “Share”.

The request will be approved.

Image showing “Joe Bloggs validated successfully as B2CVerifiedAccount”

If you have more than one VC that matches the criteria, you will be asked to select one.

At this point, you know the sample works so you can move onto part 2.

All good!

--

--

Rory Braybrook
The new control plane

NZ Microsoft Identity dude and MVP. Azure AD/B2C/ADFS/Auth0/identityserver. StackOverflow: https://bit.ly/2XU4yvJ Presentations: http://bit.ly/334ZPt5