> ## 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.

# Authentication

> Configure your Paubox API credentials for the C# SDK.

## Obtain your credentials

The Email API client requires two credentials:

* **API key**: a secret token that authenticates your requests
* **Username**: your Paubox API endpoint username (not your login email)

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

## Option 1: Constructor parameters

Pass credentials directly — useful for console apps or when managing secrets via environment variables:

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

Read from environment variables:

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

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

Add your credentials to `appsettings.json`:

```json theme={null}
{
  "APIKey": "YOUR_API_KEY",
  "APIUser": "YOUR_USERNAME"
}
```

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` and `APIUser` from the configuration and sets the `Authorization` header automatically on every request:

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

## Forms client

`FormsLibrary` requires no credentials. Instantiate it with no arguments:

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

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

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

## 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.
