arrow_back Back to developer portal

.NET

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®
  • "https://i/redirect" with your redirect URI
  • 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.RedirectUri = "https://i/redirect";
settings.PrivateJwkSet = jwks;
settings.Environment = ItsmeSettings.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 string[] { "email", "profile" };
urlConfig.ServiceCode = "my_service_code";
urlConfig.RequestUri = "";
var url = itsmeClient.GetAuthenticationURL(urlConfig);

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.

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 user = itsmeClient.GetUserDetails("authorization_code");

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.