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

## JsonWebKeyExtensions Class

Provides extensions for asynchronous operations on a sequence of [JsonWebKey](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey 'Abblix\.Jwt\.JsonWebKey') objects\.

```csharp
public static class JsonWebKeyExtensions
```

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

## JsonWebKeyExtensions\.FirstByAlgorithmAsync\(this IAsyncEnumerable\<JsonWebKey\>, string\) Method {#Abblix.Oidc.Server.Common.JsonWebKeyExtensions.FirstByAlgorithmAsync(thisSystem.Collections.Generic.IAsyncEnumerable_Abblix.Jwt.JsonWebKey_,string)}

Asynchronously retrieves the first [JsonWebKey](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey 'Abblix\.Jwt\.JsonWebKey') able to perform the specified algorithm\.

```csharp
public static System.Threading.Tasks.Task<Abblix.Jwt.JsonWebKey?> FirstByAlgorithmAsync(this System.Collections.Generic.IAsyncEnumerable<Abblix.Jwt.JsonWebKey> credentials, string? algorithm);
```
#### Parameters

###### `credentials` [System\.Collections\.Generic\.IAsyncEnumerable&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1 'System\.Collections\.Generic\.IAsyncEnumerable\`1')[JsonWebKey](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey 'Abblix\.Jwt\.JsonWebKey')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1 'System\.Collections\.Generic\.IAsyncEnumerable\`1') {#Abblix.Oidc.Server.Common.JsonWebKeyExtensions.FirstByAlgorithmAsync(thisSystem.Collections.Generic.IAsyncEnumerable_Abblix.Jwt.JsonWebKey_,string).credentials}

The asynchronous sequence of [JsonWebKey](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey 'Abblix\.Jwt\.JsonWebKey') objects\.

###### `algorithm` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Common.JsonWebKeyExtensions.FirstByAlgorithmAsync(thisSystem.Collections.Generic.IAsyncEnumerable_Abblix.Jwt.JsonWebKey_,string).algorithm}

The algorithm to match\. Returns null if [None](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.SigningAlgorithms#Abblix.Jwt.SigningAlgorithms.None 'Abblix\.Jwt\.SigningAlgorithms\.None') is provided\.

#### Returns
[System\.Threading\.Tasks\.Task&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')[JsonWebKey](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey 'Abblix\.Jwt\.JsonWebKey')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')  
The first [JsonWebKey](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey 'Abblix\.Jwt\.JsonWebKey') able to perform the algorithm\.

### Remarks
A key qualifies by declaring the algorithm, or \- when it declares none, which RFC 7517 section 4\.4 permits
and a certificate\-imported key always does \- by its material being able to perform it, per
[SupportsAlgorithm\(this JsonWebKey, string\)](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKeyExtensions#Abblix.Jwt.JsonWebKeyExtensions.SupportsAlgorithm(thisAbblix.Jwt.JsonWebKey,string) 'Abblix\.Jwt\.JsonWebKeyExtensions\.SupportsAlgorithm\(Abblix\.Jwt\.JsonWebKey,System\.String\)')\.

Order is left to the caller, deliberately. Ranking a declared `alg` above an undeclared one would
override the order the provider handed down, and that order is load-bearing: a key ring returns the active
key first, so reordering here would pick a key the ring deliberately kept behind - during a rollover, the
newcomer instead of the key clients still expect. Whether a key names its algorithm says nothing about
which key should produce.

## JsonWebKeyExtensions\.FirstByAlgorithmAsync\(this IAsyncEnumerable\<JsonWebKey\>, string, string\) Method {#Abblix.Oidc.Server.Common.JsonWebKeyExtensions.FirstByAlgorithmAsync(thisSystem.Collections.Generic.IAsyncEnumerable_Abblix.Jwt.JsonWebKey_,string,string)}

Asynchronously retrieves the first [JsonWebKey](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey 'Abblix\.Jwt\.JsonWebKey') matching an optional algorithm and an
optional key id\. This is the key\-id\-aware sibling of [FirstByAlgorithmAsync\(this IAsyncEnumerable&lt;JsonWebKey&gt;, string\)](https://www.abblix.com/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Common.JsonWebKeyExtensions#Abblix.Oidc.Server.Common.JsonWebKeyExtensions.FirstByAlgorithmAsync(thisSystem.Collections.Generic.IAsyncEnumerable_Abblix.Jwt.JsonWebKey_,string) 'Abblix\.Oidc\.Server\.Common\.JsonWebKeyExtensions\.FirstByAlgorithmAsync\(this System\.Collections\.Generic\.IAsyncEnumerable\<Abblix\.Jwt\.JsonWebKey\>, string\)'):
signing passes the token's `alg` and pinned `kid`; encryption passes a `null` algorithm
\(the key\-management `alg` is derived from the chosen key afterwards\) and only the pinned `kid`\.

```csharp
public static System.Threading.Tasks.Task<Abblix.Jwt.JsonWebKey?> FirstByAlgorithmAsync(this System.Collections.Generic.IAsyncEnumerable<Abblix.Jwt.JsonWebKey> credentials, string? algorithm, string? keyId);
```
#### Parameters

###### `credentials` [System\.Collections\.Generic\.IAsyncEnumerable&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1 'System\.Collections\.Generic\.IAsyncEnumerable\`1')[JsonWebKey](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey 'Abblix\.Jwt\.JsonWebKey')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1 'System\.Collections\.Generic\.IAsyncEnumerable\`1') {#Abblix.Oidc.Server.Common.JsonWebKeyExtensions.FirstByAlgorithmAsync(thisSystem.Collections.Generic.IAsyncEnumerable_Abblix.Jwt.JsonWebKey_,string,string).credentials}

The asynchronous sequence of [JsonWebKey](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey 'Abblix\.Jwt\.JsonWebKey') objects\.

###### `algorithm` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Common.JsonWebKeyExtensions.FirstByAlgorithmAsync(thisSystem.Collections.Generic.IAsyncEnumerable_Abblix.Jwt.JsonWebKey_,string,string).algorithm}

The algorithm to match, or `null` to not filter by algorithm\. A key qualifies
            by declaring it or, declaring none, by being able to perform it\. Returns `null` for
            [None](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.SigningAlgorithms#Abblix.Jwt.SigningAlgorithms.None 'Abblix\.Jwt\.SigningAlgorithms\.None')\.

###### `keyId` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Common.JsonWebKeyExtensions.FirstByAlgorithmAsync(thisSystem.Collections.Generic.IAsyncEnumerable_Abblix.Jwt.JsonWebKey_,string,string).keyId}

The `kid` to match, or `null` to not filter by key id\.

#### Returns
[System\.Threading\.Tasks\.Task&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')[JsonWebKey](https://www.abblix.com/docs/api/abblix-jwt/Abblix.Jwt.JsonWebKey 'Abblix\.Jwt\.JsonWebKey')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')  
The first matching key, or `null` when the sequence yields none and neither filter was
            applied\. Throws when a filter was applied but nothing matched, so a pinned key id or a required
            algorithm that resolves to no key fails loudly rather than silently downgrading\.
