A code sample using .NET framework and uses openidconnect library to enable passwordless login using Affinidi IDP.
Before you begin
Set up Affinidi Vault account. Follow the guide below if you haven’t set it up yet.
Set up Affinidi Vault
Set up an Affinidi Vault account using the Web Vault or install the Mobile Vault (for Android).
The same setup steps for Mobile Vault.
Click on Get started if you are creating a new account, or click on Restore from Backup if you have an existing backup of your Affinidi Vault. Provide the passphrase to secure your Affinidi Vault.
You have the option to enable Biometrics to unlock your Affinidi Vault easily instead of using passphrase.
GIF
Enter your email address to register with the Affinidi Vault. An OTP will be sent to this email for verification.
GIF
Enter the OTP sent to the email you have provided for verification to complete the setup.
GIF
After successfully providing the OTP, you are redirected to the Affinidi Vault dashboard.
Important Note
Remember to keep your passphrase in a secure location. Use the Passphrase Reset feature in Affinidi Vault settings to generate the PDF files and keep them safe, which you can use to recover access to your Affinidi Vault if you forget your passphrase.
Install the Affinidi CLI. Follow the guide below if it hasn’t been installed.
Set up Affinidi CLI
Download and install NodeJS on your machine if you haven’t set it up yet.
Node Version
Affinidi CLI requires Node version 18 and above.
Install Affinidi CLI using Node Package Manager (npm).
npm install -g @affinidi/cli
Verify that the installation is successful.
affinidi --version
Make sure you have Git installed on your machine. Follow this guide on how to install Git.
Install .NET SDK 8.0 if you haven’t set it up yet.
Download the Application
You can download as ZIP file the code sample from the GitHub Repo or generate it using Affinidi CLI with the following command:
Select n when prompted to Automatically configure sample app environment, we will configure it later.
The above command will generate the code sample in the affinidi-login-refcodes directory.
Important Note
The downloadable sample application is provided only as a guide to quickly explore and learn how to integrate the components of Affinidi Trust Network into your application. This is NOT a Production-ready implementation. Do not deploy this to a production environment.
Create Login Configuration
Name:Affinidi Login Sample
Redirect URIs:http://localhost:5068/signin-oidc
Using Affinidi CLI
Log in to Affinidi CLI by running:
affinidi start
Once you have successfully logged in, create the Login Configuration by running:
--name is what you want your login configuration to be called.
--redirect-uris is the URL on your application where the user gets redirected after the successful authentication.
Learn more on how to manage your Login Configurations using Affinidi CLI.
Using Affinidi Portal
In the Affinidi Elements section of the sidebar, go to Affinidi Login .
In the Configurations section, select Create configuration.
Under Configuration Details, enter the required details:
Name: a name for your own reference, shown only in Affinidi Portal.
Allowed Redirect URIs: the URLs in your application that users return to after they sign in. Enter each URI on a new line.
Optionally, expand Additional Configuration to set what users see when they sign in and how your application authenticates:
Display Name: the application name shown to users when they sign in. It defaults to the configuration name.
Origin: the URL shown to users when they sign in. It defaults to the domain of the first redirect URI.
Logo URL: the logo shown to users when they sign in. A default logo is used if you leave it empty.
Auth method: how your application authenticates when it requests an access token: Client secret basic, Client secret post, or None.
Presentation Definition and ID token mapping: the data users share when they sign in. The default requests the user’s email address. Select Edit to change it. See Edit the presentation definition in Affinidi Portal.
Select Create. The Store client secret dialog shows the Client ID, Client Secret, and Issuer for your configuration.
Copy the Client ID, Client Secret, and Issuer, and store them securely. You use them to integrate your application with Affinidi Login, and the dialog shows the Client Secret only once.
Close the dialog. Affinidi Portal opens the details page of your new configuration.
Login Configuration uses the default Presentation Definition (presentationDefinition) and ID Token Mapping (idTokenMapping) that is used to request the user’s email address during the authentication flow.
Learn more about customising the Presentation Definition and ID Token using this guide.
Important
Safeguard the Client ID and Client Secret diligently; you'll need them for setting up your IdP or OIDC-compliant applications. Remember, the Client Secret will be provided only once.
Set up the Application
Once the Login Configuration is created, set up the client credentials provided to integrate Affinidi Login.
Copy and set up the environment variables:
cp .env.example .env
Set the following variables with the values provided by the Login Configuration:
To enable a seamless passwordless login experience with Affinidi Login, refer to the following key changes were implemented:
Imported openidconnect to enable OAuth flow.
Added Affinidi Login as an OIDC provider using the function AddOpenIdConnect and configured the client credentials in the ./Startup.cs.
Explore the sample implementation to learn more about how the integration works.
Was this page helpful?
Glad to hear it! Please tell us how we can improve more.
Sorry to hear that. Please tell us how we can improve.
Thank you for sharing your feedback so we can improve your experience.
We use cookies to maintain and analyse our website performance. Where cookies have been categorised as “strictly necessary”, they are required to keep the site working but where optional we would like your consent to use them. To find out more, please see our Cookie Policy .