# ApiKeyRecord

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.apikeyrecord/
> Summary: ApiKeyRecord: An API key's database-stored view, which CARRIES no raw VALUE.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Abstractions.dll</code></div>

An API key's database-stored view, which CARRIES no raw VALUE.

```csharp
public sealed record ApiKeyRecord : IEquatable<ApiKeyRecord>
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.apikeyrecord/">ApiKeyRecord</a></dd><dt>Implements</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.iequatable-1">IEquatable&lt;ApiKeyRecord&gt;</a></dd><dt>Inherited Members</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Remarks

This record **has no** raw key. Only an irreversible
SHA-256 digest sits in the database (nowhere but [ApiKeyRecord.KeyPrefix](/api/tracon.apikeyrecord/#Tracon_ApiKeyRecord_KeyPrefix));
the raw value is returned **once**, only at creation time,
via [ApiKeyCreationResult.PlaintextKey](/api/tracon.apikeycreationresult/#Tracon_ApiKeyCreationResult_PlaintextKey).

## Constructors

### <a id="Tracon_ApiKeyRecord__ctor"></a> ApiKeyRecord\(\)

```csharp
public ApiKeyRecord()
```

## Properties

### <a id="Tracon_ApiKeyRecord_CreatedAt"></a> CreatedAt

The creation time (UTC).

```csharp
public required DateTimeOffset CreatedAt { get; init; }
```

#### Property Value

 [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset)

### <a id="Tracon_ApiKeyRecord_ExpiresAt"></a> ExpiresAt

The expiration. Never expires if [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

```csharp
public DateTimeOffset? ExpiresAt { get; init; }
```

#### Property Value

 [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset)?

### <a id="Tracon_ApiKeyRecord_Id"></a> Id

The key identifier.

```csharp
public required Guid Id { get; init; }
```

#### Property Value

 [Guid](https://learn.microsoft.com/dotnet/api/system.guid)

### <a id="Tracon_ApiKeyRecord_IsActive"></a> IsActive

[true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the key is not revoked and has not expired.

```csharp
public bool IsActive { get; }
```

#### Property Value

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

#### Remarks

For DISPLAY ONLY (the UI list, `GET /api/api-keys`). The actual
authentication decision is made in `ApiKeyAuthenticator` with an
injected [TimeProvider](https://learn.microsoft.com/dotnet/api/system.timeprovider); using
[DateTimeOffset.UtcNow](https://learn.microsoft.com/dotnet/api/system.datetimeoffset) here is not a security decision
and does not affect testability.

### <a id="Tracon_ApiKeyRecord_KeyPrefix"></a> KeyPrefix

The raw value's first characters; used to distinguish the key in a list.

```csharp
public required string KeyPrefix { get; init; }
```

#### Property Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)

### <a id="Tracon_ApiKeyRecord_LastUsedAt"></a> LastUsedAt

The last-used time. Used to spot an unused key.

```csharp
public DateTimeOffset? LastUsedAt { get; init; }
```

#### Property Value

 [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset)?

### <a id="Tracon_ApiKeyRecord_Name"></a> Name

The name for the operator to recognize the key by.

```csharp
public required string Name { get; init; }
```

#### Property Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)

### <a id="Tracon_ApiKeyRecord_RevokedAt"></a> RevokedAt

The revocation timestamp. The row is not DELETED; the audit trail is preserved through this field.

```csharp
public DateTimeOffset? RevokedAt { get; init; }
```

#### Property Value

 [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset)?

### <a id="Tracon_ApiKeyRecord_Scopes"></a> Scopes

The scope set. The effective authority is `role ∩ scope`.

```csharp
public required IReadOnlyList<ApiKeyScope> Scopes { get; init; }
```

#### Property Value

 [IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist\-1)<[ApiKeyScope](/api/tracon.apikeyscope/)\>

### <a id="Tracon_ApiKeyRecord_TenantId"></a> TenantId

The tenant the key is bound to. On authentication, the tenant is resolved FROM HERE.

```csharp
public required string TenantId { get; init; }
```

#### Property Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)

## Methods

### <a id="Tracon_ApiKeyRecord_Equals_System_Object_"></a> Equals\(object?\)

```csharp
public override bool Equals(object? obj)
```

#### Parameters

`obj` [object](https://learn.microsoft.com/dotnet/api/system.object)?

#### Returns

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### <a id="Tracon_ApiKeyRecord_Equals_Tracon_ApiKeyRecord_"></a> Equals\(ApiKeyRecord?\)

```csharp
public bool Equals(ApiKeyRecord? other)
```

#### Parameters

`other` [ApiKeyRecord](/api/tracon.apikeyrecord/)?

#### Returns

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### <a id="Tracon_ApiKeyRecord_GetHashCode"></a> GetHashCode\(\)

```csharp
public override int GetHashCode()
```

#### Returns

 [int](https://learn.microsoft.com/dotnet/api/system.int32)

### <a id="Tracon_ApiKeyRecord_ToString"></a> ToString\(\)

```csharp
public override string ToString()
```

#### Returns

 [string](https://learn.microsoft.com/dotnet/api/system.string)

## Operators

### <a id="Tracon_ApiKeyRecord_op_Equality_Tracon_ApiKeyRecord_Tracon_ApiKeyRecord_"></a> operator ==\(ApiKeyRecord?, ApiKeyRecord?\)

```csharp
public static bool operator ==(ApiKeyRecord? left, ApiKeyRecord? right)
```

#### Parameters

`left` [ApiKeyRecord](/api/tracon.apikeyrecord/)?

`right` [ApiKeyRecord](/api/tracon.apikeyrecord/)?

#### Returns

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

### <a id="Tracon_ApiKeyRecord_op_Inequality_Tracon_ApiKeyRecord_Tracon_ApiKeyRecord_"></a> operator \!=\(ApiKeyRecord?, ApiKeyRecord?\)

```csharp
public static bool operator !=(ApiKeyRecord? left, ApiKeyRecord? right)
```

#### Parameters

`left` [ApiKeyRecord](/api/tracon.apikeyrecord/)?

`right` [ApiKeyRecord](/api/tracon.apikeyrecord/)?

#### Returns

 [bool](https://learn.microsoft.com/dotnet/api/system.boolean)
