Setup an OIDC Client app

Most verifiers or relying parties will want to request information from a user's verifiable credential during a particular workflow, perhaps as an onboarding step or a confirmation before proceeding to do something with the information.

Exactly how and when to achieve this depends on your existing systems or external processes you need to integrate with. For the purpose of this tutorial we will demonstrate a basic user journey, so we're going to use a simple standards-based OpenID Connect Client application that you can configure and run locally.

Prerequisites

You need the following in order to proceed with this tutorial:

Set up a Client to use PKCE

Because we will be running the OIDC Client as a native-like app (also known as a Single-Page-App) you will need to setup the Client on the Verifier in a certain way:

PKCE is not a requirement for using the OIDC Credential Verifier, if you were to run a more traditional server based authorization flow then the client app can be configured in a similar way to how you Configure an OIDC Client.

json
Copy to clipboard.
1{
2  "name": "Verify React OIDC Sample App",
3  "redirectUris": [
4    "https://localhost:3000/signin-callback.html"
5  ],
6  "responseTypes": [
7    "code"
8  ],
9  "grantTypes": [
10    "authorization_code"
11  ],
12  "tokenEndpointAuthMethod": "none",
13  "idTokenSignedResponseAlg": "ES256",
14  "applicationType": "native",
15  "logoUri": "https://learn.mattr.global/MATTR-logo_light-full.svg"
16}

Technically you will not be requiring a secret on the Token endpoint and the application type can be considered as native. This will setup your client to accept a Proof Key Code Exchange or 'PKCE' often referred to as 'Pixie'.

There are lots of good guides about why PKCE is the preferred method of using OIDC with clients and how the 'implicit' flow is strongly not recommended when transferring sensitive data, such as often found in Credentials.

Get the sample app

1. Go to the MATTR Github sample apps repo.

2. Clone the repo:

shell
Copy to clipboard.
1git clone https://github.com/mattrglobal/sample-apps

3. Change to the dir and install dependencies:

shell
Copy to clipboard.
1cd react-oidc-client
2
3yarn install

4. Rename the `.env-template` file to `.env` and add your variable:

Copy to clipboard.
REACT_APP_STSAUTHORITY=https://<your-tenant>.vii.mattr.global/ext/oidc/v1/verifiers/<verifier-id>

REACT_APP_CLIENTID=<client-id>

REACT_APP_CLIENTROOT=https://localhost:3000/

REACT_APP_CLIENTSCOPE=openid_credential_presentation

Note the mandatory `openid` scope is always automatically added to the Authorization Request in the first position as per OpenID Connect Core spec.

Try it out

If you have everything configured correctly, then go ahead and start the demo app in a development server on your local machine.

1. Start the app:

yarn start

The app should open a browser window, if not navigate to `https://localhost:3000` and you should see the MATTR OIDC Client Demo App home screen:

https://www.datocms-assets.com/38428/1621284506-mattr-oidc-reactapp.webp?auto=format

2. Click on the 'Verify' button to start the Verify Credential via OIDC flow!

Its a good idea to have your browser dev-tools open at this point, switch on 'preserve log' so you can follow the redirect requests across sites.

If the redirect fails with 'oops! something went wrong' screen -- check that the redirect Uri configured in the Client matches the value configured in your `.env` file, and that the React app started on the port specified e.g. `https://localhost:3000`.

The app will construct the OAuth2/OIDC Authorization Request and navigate you to the OIDC Credential Verifier instance configured in the `REACT_APP_STSAUTHORITY` variable, it will contain the `REACT_APP_CLIENTID` as a query parameter, along with the required OAuth2 parameters `state`, `login` and `scope` (containing both `openid` and the `opendID_credential_presentation` values) as well as the PKCE `code_challenge` and `code_challenge_method` parameters, which trigger the PKCE flow.

http
Copy to clipboard.
1https://YOUR_TENANT_URL/ext/oidc/v1/verifiers/dd6e3caa-7b41-4b95-afca-4dc1c41295f7/authorizehttps://tenant.vii.mattr.global/ext/oidc/v1/verifiers/dd6e3caa-7b41-4b95-afca-4dc1c41295f7/authorize
2
3?client_id=7fa513fa-0c5b-448b-b61e-0e33e4823012
4
5&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fsignin-callback.html
6
7&response_type=code
8
9&scope=openid%20openid_credential_presentation
10
11&state=66a8fe1fdca84d978edc9f1ec99c78d6
12
13&prompt=login
14
15&code_challenge=9U3GmYdjm8z3tZKS8VIxmhhRqPYA8b3JzKRiFMOglX0
16
17&code_challenge_method=S256