#### [Abblix\.Oidc\.Server](https://www.abblix.com/en/docs/api/abblix-oidc-server 'index')
### [Abblix\.Oidc\.Server\.Features\.DeviceAuthorization](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.DeviceAuthorization 'Abblix\.Oidc\.Server\.Features\.DeviceAuthorization')

## DeviceAuthorizationStorage Class

Implements storage for device authorization requests as defined in RFC 8628\.
Stores requests by device\_code \(for client polling\) with a secondary index by user\_code \(for user verification\)\.
Uses atomic distributed cache operations to prevent race conditions in token issuance\.

```csharp
public class DeviceAuthorizationStorage : Abblix.Oidc.Server.Features.DeviceAuthorization.Interfaces.IDeviceAuthorizationStorage
```

Inheritance [System\.Object](https://learn.microsoft.com/en-us/dotnet/api/system.object 'System\.Object') → DeviceAuthorizationStorage

Implements [IDeviceAuthorizationStorage](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.DeviceAuthorization.Interfaces.IDeviceAuthorizationStorage 'Abblix\.Oidc\.Server\.Features\.DeviceAuthorization\.Interfaces\.IDeviceAuthorizationStorage')
### Constructors

## DeviceAuthorizationStorage\(IDistributedCache, IBinarySerializer, IEntityStorageKeyFactory, TimeProvider\) Constructor {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.DeviceAuthorizationStorage(Microsoft.Extensions.Caching.Distributed.IDistributedCache,Abblix.Oidc.Server.Common.Interfaces.IBinarySerializer,Abblix.Oidc.Server.Features.Storages.IEntityStorageKeyFactory,System.TimeProvider)}

Implements storage for device authorization requests as defined in RFC 8628\.
Stores requests by device\_code \(for client polling\) with a secondary index by user\_code \(for user verification\)\.
Uses atomic distributed cache operations to prevent race conditions in token issuance\.

```csharp
public DeviceAuthorizationStorage(Microsoft.Extensions.Caching.Distributed.IDistributedCache cache, Abblix.Oidc.Server.Common.Interfaces.IBinarySerializer serializer, Abblix.Oidc.Server.Features.Storages.IEntityStorageKeyFactory keyFactory, System.TimeProvider timeProvider);
```
#### Parameters

###### `cache` [Microsoft\.Extensions\.Caching\.Distributed\.IDistributedCache](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.distributed.idistributedcache 'Microsoft\.Extensions\.Caching\.Distributed\.IDistributedCache') {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.DeviceAuthorizationStorage(Microsoft.Extensions.Caching.Distributed.IDistributedCache,Abblix.Oidc.Server.Common.Interfaces.IBinarySerializer,Abblix.Oidc.Server.Features.Storages.IEntityStorageKeyFactory,System.TimeProvider).cache}

The distributed cache backend used for atomic operations\.

###### `serializer` [IBinarySerializer](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Common.Interfaces.IBinarySerializer 'Abblix\.Oidc\.Server\.Common\.Interfaces\.IBinarySerializer') {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.DeviceAuthorizationStorage(Microsoft.Extensions.Caching.Distributed.IDistributedCache,Abblix.Oidc.Server.Common.Interfaces.IBinarySerializer,Abblix.Oidc.Server.Features.Storages.IEntityStorageKeyFactory,System.TimeProvider).serializer}

The serializer for converting objects to/from binary format\.

###### `keyFactory` [IEntityStorageKeyFactory](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.Storages.IEntityStorageKeyFactory 'Abblix\.Oidc\.Server\.Features\.Storages\.IEntityStorageKeyFactory') {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.DeviceAuthorizationStorage(Microsoft.Extensions.Caching.Distributed.IDistributedCache,Abblix.Oidc.Server.Common.Interfaces.IBinarySerializer,Abblix.Oidc.Server.Features.Storages.IEntityStorageKeyFactory,System.TimeProvider).keyFactory}

The factory for generating standardized storage keys\.

###### `timeProvider` [System\.TimeProvider](https://learn.microsoft.com/en-us/dotnet/api/system.timeprovider 'System\.TimeProvider') {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.DeviceAuthorizationStorage(Microsoft.Extensions.Caching.Distributed.IDistributedCache,Abblix.Oidc.Server.Common.Interfaces.IBinarySerializer,Abblix.Oidc.Server.Features.Storages.IEntityStorageKeyFactory,System.TimeProvider).timeProvider}

Provides the current time for seeding the request's absolute expiry\.
### Methods

## DeviceAuthorizationStorage\.RemoveAsync\(string\) Method {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.RemoveAsync(string)}

Removes a device authorization request from storage using its device code\.

```csharp
public System.Threading.Tasks.Task RemoveAsync(string deviceCode);
```
#### Parameters

###### `deviceCode` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.RemoveAsync(string).deviceCode}

The device code identifier\.

Implements [RemoveAsync\(string\)](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.DeviceAuthorization.Interfaces.IDeviceAuthorizationStorage#Abblix.Oidc.Server.Features.DeviceAuthorization.Interfaces.IDeviceAuthorizationStorage.RemoveAsync(string) 'Abblix\.Oidc\.Server\.Features\.DeviceAuthorization\.Interfaces\.IDeviceAuthorizationStorage\.RemoveAsync\(string\)')

#### Returns
[System\.Threading\.Tasks\.Task](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task 'System\.Threading\.Tasks\.Task')  
A task that completes when the request is removed from storage\.

## DeviceAuthorizationStorage\.StoreAsync\(string, DeviceAuthorizationRequest, TimeSpan\) Method {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.StoreAsync(string,Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest,System.TimeSpan)}

Stores a device authorization request with the specified device code\.

```csharp
public System.Threading.Tasks.Task StoreAsync(string deviceCode, Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest request, System.TimeSpan expiresIn);
```
#### Parameters

###### `deviceCode` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.StoreAsync(string,Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest,System.TimeSpan).deviceCode}

The unique device code identifier\.

###### `request` [DeviceAuthorizationRequest](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest 'Abblix\.Oidc\.Server\.Features\.DeviceAuthorization\.DeviceAuthorizationRequest') {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.StoreAsync(string,Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest,System.TimeSpan).request}

The device authorization request to store\.

###### `expiresIn` [System\.TimeSpan](https://learn.microsoft.com/en-us/dotnet/api/system.timespan 'System\.TimeSpan') {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.StoreAsync(string,Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest,System.TimeSpan).expiresIn}

The duration after which the stored request will expire\.

Implements [StoreAsync\(string, DeviceAuthorizationRequest, TimeSpan\)](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.DeviceAuthorization.Interfaces.IDeviceAuthorizationStorage#Abblix.Oidc.Server.Features.DeviceAuthorization.Interfaces.IDeviceAuthorizationStorage.StoreAsync(string,Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest,System.TimeSpan) 'Abblix\.Oidc\.Server\.Features\.DeviceAuthorization\.Interfaces\.IDeviceAuthorizationStorage\.StoreAsync\(string, Abblix\.Oidc\.Server\.Features\.DeviceAuthorization\.DeviceAuthorizationRequest, System\.TimeSpan\)')

#### Returns
[System\.Threading\.Tasks\.Task](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task 'System\.Threading\.Tasks\.Task')  
A task that completes when the request is stored\.

## DeviceAuthorizationStorage\.TryGetByDeviceCodeAsync\(string\) Method {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.TryGetByDeviceCodeAsync(string)}

Tries to retrieve a device authorization request by its device code\.
This is used by the client when polling the token endpoint\.

```csharp
public System.Threading.Tasks.Task<Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest?> TryGetByDeviceCodeAsync(string deviceCode);
```
#### Parameters

###### `deviceCode` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.TryGetByDeviceCodeAsync(string).deviceCode}

The device code identifier\.

Implements [TryGetByDeviceCodeAsync\(string\)](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.DeviceAuthorization.Interfaces.IDeviceAuthorizationStorage#Abblix.Oidc.Server.Features.DeviceAuthorization.Interfaces.IDeviceAuthorizationStorage.TryGetByDeviceCodeAsync(string) 'Abblix\.Oidc\.Server\.Features\.DeviceAuthorization\.Interfaces\.IDeviceAuthorizationStorage\.TryGetByDeviceCodeAsync\(string\)')

#### Returns
[System\.Threading\.Tasks\.Task&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')[DeviceAuthorizationRequest](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest 'Abblix\.Oidc\.Server\.Features\.DeviceAuthorization\.DeviceAuthorizationRequest')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')  
A task that returns the device authorization request if found; otherwise, null\.

## DeviceAuthorizationStorage\.TryGetByUserCodeAsync\(string\) Method {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.TryGetByUserCodeAsync(string)}

Tries to retrieve a device authorization request by its user code\.
This is used during user verification to look up the pending request\.

```csharp
public System.Threading.Tasks.Task<System.Nullable<(string DeviceCode,Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest Request)>> TryGetByUserCodeAsync(string userCode);
```
#### Parameters

###### `userCode` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.TryGetByUserCodeAsync(string).userCode}

The user\-friendly verification code\.

Implements [TryGetByUserCodeAsync\(string\)](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.DeviceAuthorization.Interfaces.IDeviceAuthorizationStorage#Abblix.Oidc.Server.Features.DeviceAuthorization.Interfaces.IDeviceAuthorizationStorage.TryGetByUserCodeAsync(string) 'Abblix\.Oidc\.Server\.Features\.DeviceAuthorization\.Interfaces\.IDeviceAuthorizationStorage\.TryGetByUserCodeAsync\(string\)')

#### Returns
[System\.Threading\.Tasks\.Task&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')[System\.Nullable&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 'System\.Nullable\`1')[&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.valuetuple 'System\.ValueTuple')[System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String')[,](https://learn.microsoft.com/en-us/dotnet/api/system.valuetuple 'System\.ValueTuple')[DeviceAuthorizationRequest](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest 'Abblix\.Oidc\.Server\.Features\.DeviceAuthorization\.DeviceAuthorizationRequest')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.valuetuple 'System\.ValueTuple')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 'System\.Nullable\`1')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')  
A task that returns the device code and request if found; otherwise, null\.

## DeviceAuthorizationStorage\.TryRemoveAsync\(string, string\) Method {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.TryRemoveAsync(string,string)}

Atomically attempts to remove a device authorization request by device code\.
Uses lock\-based atomic removal protocol to prevent race conditions where multiple threads
attempt to remove the same device code concurrently\.

```csharp
public System.Threading.Tasks.Task<bool> TryRemoveAsync(string deviceCode, string userCode);
```
#### Parameters

###### `deviceCode` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.TryRemoveAsync(string,string).deviceCode}

The device code identifying the authorization request to remove\.

###### `userCode` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.TryRemoveAsync(string,string).userCode}

The user code for cleaning up the secondary index mapping\.

Implements [TryRemoveAsync\(string, string\)](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.DeviceAuthorization.Interfaces.IDeviceAuthorizationStorage#Abblix.Oidc.Server.Features.DeviceAuthorization.Interfaces.IDeviceAuthorizationStorage.TryRemoveAsync(string,string) 'Abblix\.Oidc\.Server\.Features\.DeviceAuthorization\.Interfaces\.IDeviceAuthorizationStorage\.TryRemoveAsync\(string, string\)')

#### Returns
[System\.Threading\.Tasks\.Task&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')[System\.Boolean](https://learn.microsoft.com/en-us/dotnet/api/system.boolean 'System\.Boolean')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')  
A task that completes when the operation finishes, containing true if the request was successfully
removed by this thread; false if another thread won the race or the device code didn't exist\.

### Remarks

This method performs atomic removal of both the device code entry and its associated user code
mapping. By accepting the userCode as a parameter, it avoids an additional cache read operation,
since the caller already has this information from a previous fetch.

<strong>Use Case:</strong> This method is used in the Device Authorization Grant flow (RFC 8628)
            when exchanging an authorized device code for tokens. The atomic removal ensures that concurrent
            token requests cannot both claim the same device code.

<strong>Atomicity:</strong> Uses [Abblix\.Utils\.DistributedCacheExtensions\.TryRemoveAsync\(Microsoft\.Extensions\.Caching\.Distributed\.IDistributedCache,System\.String,System\.Nullable\{System\.TimeSpan\},System\.Threading\.CancellationToken\)](https://learn.microsoft.com/en-us/dotnet/api/abblix.utils.distributedcacheextensions.tryremoveasync#abblix-utils-distributedcacheextensions-tryremoveasync(microsoft-extensions-caching-distributed-idistributedcache-system-string-system-nullable{system-timespan}-system-threading-cancellationtoken) 'Abblix\.Utils\.DistributedCacheExtensions\.TryRemoveAsync\(Microsoft\.Extensions\.Caching\.Distributed\.IDistributedCache,System\.String,System\.Nullable\{System\.TimeSpan\},System\.Threading\.CancellationToken\)')
            which implements a lock-based protocol ensuring exactly one thread successfully removes the value
            even in concurrent scenarios. After successful removal, cleans up the user code mapping.

## DeviceAuthorizationStorage\.UpdateAsync\(string, DeviceAuthorizationRequest, TimeSpan\) Method {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.UpdateAsync(string,Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest,System.TimeSpan)}

Updates an existing device authorization request in storage, refreshing its cache entry with the
caller\-supplied remaining lifetime\.

```csharp
public System.Threading.Tasks.Task UpdateAsync(string deviceCode, Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest request, System.TimeSpan expiresIn);
```
#### Parameters

###### `deviceCode` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.UpdateAsync(string,Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest,System.TimeSpan).deviceCode}

The device code identifier\.

###### `request` [DeviceAuthorizationRequest](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest 'Abblix\.Oidc\.Server\.Features\.DeviceAuthorization\.DeviceAuthorizationRequest') {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.UpdateAsync(string,Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest,System.TimeSpan).request}

The updated device authorization request\.

###### `expiresIn` [System\.TimeSpan](https://learn.microsoft.com/en-us/dotnet/api/system.timespan 'System\.TimeSpan') {#Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationStorage.UpdateAsync(string,Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest,System.TimeSpan).expiresIn}

The remaining lifetime to apply as the cache TTL\. The caller derives it from
            the request's fixed expiry \(RFC 8628 §3\.2\) so that repeated polling cannot extend the code\.

Implements [UpdateAsync\(string, DeviceAuthorizationRequest, TimeSpan\)](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.DeviceAuthorization.Interfaces.IDeviceAuthorizationStorage#Abblix.Oidc.Server.Features.DeviceAuthorization.Interfaces.IDeviceAuthorizationStorage.UpdateAsync(string,Abblix.Oidc.Server.Features.DeviceAuthorization.DeviceAuthorizationRequest,System.TimeSpan) 'Abblix\.Oidc\.Server\.Features\.DeviceAuthorization\.Interfaces\.IDeviceAuthorizationStorage\.UpdateAsync\(string, Abblix\.Oidc\.Server\.Features\.DeviceAuthorization\.DeviceAuthorizationRequest, System\.TimeSpan\)')

#### Returns
[System\.Threading\.Tasks\.Task](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task 'System\.Threading\.Tasks\.Task')  
A task that completes when the request is updated\.
