> ## Documentation Index
> Fetch the complete documentation index at: https://docs.paubox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C# SDK authentication

> Configure Paubox API credentials for the C# SDK with a constructor parameter or IConfiguration in ASP.NET Core, plus Forms client setup and security notes.

## Obtain your API key

The Email API client requires a single credential:

* **API key**: a secret token that authenticates your requests

It is available in the [Paubox dashboard](https://next.paubox.com) under **API Credentials**.

## Option 1: Constructor parameter

Pass your API key directly; useful for console apps or when managing secrets via environment variables:

```csharp theme={null}
var emailLib = new EmailLibrary("YOUR_API_KEY");
```

Read from an environment variable:

```csharp theme={null}
var emailLib = new EmailLibrary(
    Environment.GetEnvironmentVariable("PAUBOX_API_KEY")
);
```

## Option 2: IConfiguration (recommended for ASP.NET Core)

Add your API key to `appsettings.json`:

```json theme={null}
{
  "APIKey": "YOUR_API_KEY"
}
```

Then inject `IConfiguration` and pass it to the constructor:

```csharp theme={null}
// In Program.cs or Startup.cs
builder.Services.AddSingleton<IEmailLibrary>(sp =>
{
    var config = sp.GetRequiredService<IConfiguration>();
    return new EmailLibrary(config);
});
```

Or instantiate directly:

```csharp theme={null}
var emailLib = new EmailLibrary(configuration);
```

The SDK reads `APIKey` from the configuration and sets the `Authorization` header automatically on every request:

```
Authorization: Token token=YOUR_API_KEY
```

## Forms client

`GetForm` and `SubmitForm` are public and need no credentials:

```csharp theme={null}
var formsLib = new FormsLibrary();
```

All other Forms methods need an API key with the `forms` scope, sent as `Authorization: Bearer YOUR_API_KEY`. Pass it to the constructor, or set `FormsAPIKey` (and optionally `FormsBaseURL`) in configuration:

```csharp theme={null}
var formsLib = new FormsLibrary("YOUR_API_KEY");

// Or read FormsAPIKey from IConfiguration
var configuredFormsLib = new FormsLibrary(configuration);
```

Use `IFormsLibrary` in ASP.NET Core for dependency injection and testability:

```csharp theme={null}
builder.Services.AddSingleton<IFormsLibrary, FormsLibrary>();
```

## Receiving and webhook clients

`ReceivingLibrary` takes the same API key as `EmailLibrary`, either as a constructor argument or from `APIKey` in configuration.

`WebhookLibrary` needs a scoped API key, sent as `Authorization: Bearer YOUR_API_KEY`. Pass it to the constructor, or set `WebhooksAPIKey` (and optionally `WebhooksBaseURL`) in configuration. See [Webhook client](https://docs.paubox.com/csharp-sdk/webhook-client.md).

## Security notes

* Never hard-code credentials in source files. Use `appsettings.json` with user secrets or environment variables.
* Use [.NET user secrets](https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets) during development to keep credentials out of source control.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.