# Configuration and Setup

## Introduction

This guide walks through configuring Abblix OIDC Server in a .NET project for customers with a commercial license. It covers package installation and the licensing options you can choose between, so you can get the project running quickly and predictably.

## Install Abblix NuGet Package

Abblix delivers its OIDC Server as a set of NuGet packages available on [nuget.org](https://www.nuget.org/packages/Abblix.OIDC.Server.MVC).

- Open a terminal or command prompt in the root directory of your solution.
- Run the following command to install the package:
  ```bash
  dotnet add package Abblix.OIDC.Server.Mvc
  ```
  or for a specific version:
  ```bash
  dotnet add package Abblix.OIDC.Server.Mvc --version <version_number>
  ```
- This will add the package reference directly to your project file.

## Apply the License

:::note[Without a license]
If you skip this step, the server runs in a free-tier fallback mode that allows up to 2 clients and 1 issuer. Beyond those limits the server logs license-violation errors every 15 minutes; once the client count exceeds the limit by more than 30%, new clients are rejected, and registering a second issuer throws `InvalidOperationException` with the message *"The license terms violation detected"*. This mode is intended for evaluation only. Production deployments must apply a valid license.

If you plan to use Abblix OIDC Server for a non-commercial project, [contact us](mailto:support@abblix.com). We will prepare a special license for you, free of charge.
:::

There are several different options to apply your Abblix OIDC Server license. Pick whichever is most convenient:

### Use Inline License Configuration

This method sets the license key directly in your application's startup configuration. You can retrieve the key from environment variables, configuration files, or a secure vault, then set it as shown below:

- In your application's startup configuration (e.g., `Program.cs` or equivalent), add the following code:
  ```csharp
  builder.Services.AddOidcServices(options =>
  {
      options.LicenseJwt = "<your_license_key_here>";
  });
  ```
The advantage of this approach is its simplicity.

### Implement ILicenseJwtProvider

This method is more flexible: implement the `ILicenseJwtProvider` interface to obtain the license dynamically.
The custom implementation of `ILicenseJwtProvider` can rely on services configured during startup to obtain the license.
It also supports loading multiple licenses simultaneously, which lets you migrate from an old license to a new one without downtime when both are loaded.

- Create a new class that implements the `ILicenseJwtProvider` interface:
  ```csharp
  using System;
  using System.Collections.Generic;
  using Abblix.Oidc.Server.Features.Licensing;

  public class CustomLicenseJwtProvider : ILicenseJwtProvider
  {
      public async IAsyncEnumerable<string> GetLicenseJwtAsync()
      {
          // Retrieve the license JWT(s), for example, from environment variables or configuration
          var licenseJwt = Environment.GetEnvironmentVariable("ABBLIX_OIDC_LICENSE_KEY");
          if (!string.IsNullOrWhiteSpace(licenseJwt))
              yield return licenseJwt;
      }
  }
  ```

- In Program.cs, add the following code to register the custom provider:
  ```csharp
  builder.Services.AddSingleton<ILicenseJwtProvider, CustomLicenseJwtProvider>();
  builder.Services.AddOidcServices(options => { /* configure as needed */ });
  ```

## Register OIDC Services in Program.cs

With the package installed and the license configured, the minimum wiring needed in `Program.cs` for the server to start is:

```csharp
using Abblix.Oidc.Server.Mvc;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllersWithViews();

// Register and configure the OIDC server.
builder.Services.AddOidcServices(options =>
{
    // Configure your clients, login URI, signing keys, and any other options here.
});

// Cookie authentication is required so the server can sign the user in
// after a successful login.
builder.Services
    .AddAuthentication()
    .AddCookie();

// Abblix OIDC Server persists authorization codes, PAR requests, and JWT
// statuses through IDistributedCache. MemoryCache works for development;
// production should use a real distributed backend (Redis, SQL Server, NCache,
// Memcached, Couchbase, ...).
builder.Services.AddDistributedMemoryCache();

var app = builder.Build();

app.UseRouting();
app.UseCors();
app.UseAuthorization();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();
```

That is the smallest setup that will boot the server. For a full end-to-end walkthrough (defining clients, building a login UI, plugging in user storage, and connecting a client application), follow the [Getting Started guide](https://www.abblix.com/en/docs/getting-started-guide).

## Finalizing the Setup

### Verify Setup

- Ensure the application runs without any licensing errors.
- Check that the features specific to the commercial license are accessible.

For advanced configurations, contact our [support team](mailto:support@abblix.com).
