arrow_back Back to developer portal

.NET

Currently the DotNet Core Nuget package only supports a 64 bit Windows environment. We are working towards cross platform compatibility targetted at the first half of 2020.

The full itsme® DotNet Core code sample snippet can be found here.

Installation

Install the itsme® NuGet package to your project to get started.

$ dotnet add <myproject> itsme

Import the itsme® project into your code.

using Itsme;

Configure the itsme® client

Initialize the itsme® client with your configuration. Replace the relevant parts with your data:

  • my_private_jwks.json with your actual key file content
  • my_client_id with the client ID received by itsme®
  • ItsmeSettings.Production by the environment you want to use
var jwks = File.ReadAllText("jwks_private.json");
var settings = new ItsmeSettings();
settings.ClientId = "my_client_id";
settings.PrivateJwkSet = jwks;
settings.Environment = Itsme.Environment.production;
var itsmeClient = new Client(settings);

Request user authentication

Create a URI that starts the user identification by providing the needed configuration.

  • The scopes you want to use
  • my_service_code with the service received by itsme® for the relevant service
  • Add a RequestUri in case your want to use one
var urlConfig = new UrlConfiguration();
urlConfig.Scopes = new List<Itsme.Scope>(){
    Itsme.Scope.profile,
    Itsme.Scope.email,
    Itsme.Scope.address,
    Itsme.Scope.phone
};
urlConfig.ServiceCode = "MY_SERVICE_CODE";
urlConfig.RedirectUri = "https://example.com/production/redirect";
var url = itsmeClient.GetAuthenticationURL(urlConfig);

Building the request uri payload

In case you need additional data from the user or want to use a different service requiring the use of a request_uri, you can create the signed and encrypted JWT using the built-in CreateRequestURIPayload function.

Login sample

var requestSettings = new Itsme.RequestUriConfiguration();
requestSettings.ServiceCode = "MY_SERVICE_CODE";
requestSettings.Scopes = new List<Itsme.Scope>(){
    Itsme.Scope.profile,
    Itsme.Scope.email,
    Itsme.Scope.address,
    Itsme.Scope.phone
};
requestSettings.RedirectUri = "https://example.com/production/redirect";
requestSettings.AcrValue = Itsme.AcrValue.ACRAdvanced;
requestSettings.Nonce = "a_valid_nonce";
requestSettings.State = "a_valid_state";
var data = itsmeClient.CreateRequestURIPayload(requestSettings);

The possible ACRValue values are:

  • ACRBasic - Allow fingerprint authentication
  • ACRAdvanced - Force PIN entry

Share data sample

The Share data service differs itself from the Login service in that you must at least specify one Claim in the request_uri object.

requestSettings.Claims = new List<Itsme.Claim>(){
    Itsme.Claim.ClaimEid,
    Itsme.Claim.ClaimCityOfBirth
};

The following Claims are available:

  • ClaimEid - Request the user’s E-ID data
  • ClaimCityOfBirth - Request the user’s city of birth
  • ClaimNationality - Request the user’s nationality
  • ClaimDevice - Request the user’s device information
  • ClaimPhoto - Request the user’s profile picture

If the user is successfully authenticated and authorises access to the data requested, itsme® will return a code to your server component. This is achieved by returning an Authentication Response, which is a HTTP 302 redirect request to the redirect URI specified previously.

Confirm sample

When using the Confirm service you have the option to use two templates, free text and advanced payment.

Free text allows you to add a guiding text containing more stylized content to offer information to the user in the itsme® app. The following charcters are supported:

  • <i> for italic text
  • <b> for bold text
  • <u> for underlined text
  • </br> for line breaks
requestSettings.FreeTextTemplate = new Itsme.FreeTextTemplate();
requestSettings.FreeTextTemplate.Text = "This is <b>me</b> in bold.</br>This is <i>me</i> in italic.</br>This is <u>me</u> in underline.";

Advanced payment is used when you want to add contextual information regarding a payment transfer. The itsme® app will render it a layout highlighting this information to the user.

requestSettings.AdvancedPaymentTemplate = new Itsme.AdvancedPaymentTemplate();
requestSettings.AdvancedPaymentTemplate.Amount = "20";
requestSettings.AdvancedPaymentTemplate.Currency = "EUR";
requestSettings.AdvancedPaymentTemplate.IBAN = "BE68539007547034";

Retrieve the user’s unique identifier and attributes

Once your server component has received a code, it can exchange it for an user’s unique identifier and his attributes.

var data = new Itsme.RedirectData();
data.Code = authorization_code;
data.RedirectUri = "https://example.com/production/redirect";
var user = itsmeClient.GetUserDetails(data);

Make sure to only use the sub identifier to link or reference an itsme® user from your data as all other parameters can be subject to change.