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

## IAuthorizationCodeService Interface

Provides a contract for managing OAuth 2\.0 authorization codes, facilitating the authorization code flow\.
This interface enables the generation of unique authorization codes for authenticated sessions, the validation
of these codes for user authorization, and the subsequent removal of codes once they have been used or expired,
ensuring adherence to the OAuth 2\.0 specification\.

```csharp
public interface IAuthorizationCodeService
```

Derived  
↳ [AuthorizationCodeService](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.Storages.AuthorizationCodeService 'Abblix\.Oidc\.Server\.Features\.Storages\.AuthorizationCodeService')
### Methods

## IAuthorizationCodeService\.AuthorizeByCodeAsync\(string\) Method {#Abblix.Oidc.Server.Features.Storages.IAuthorizationCodeService.AuthorizeByCodeAsync(string)}

Validates an authorization code and processes the authorization request, authorizing the user
and granting access based on the code provided\. This method verifies the code's validity, ensuring it
matches a previously issued code and has not expired or been used\.

```csharp
System.Threading.Tasks.Task<Abblix.Utils.Result<Abblix.Oidc.Server.Endpoints.Token.Interfaces.AuthorizedGrant,Abblix.Oidc.Server.Common.OidcError>> AuthorizeByCodeAsync(string authorizationCode);
```
#### Parameters

###### `authorizationCode` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Features.Storages.IAuthorizationCodeService.AuthorizeByCodeAsync(string).authorizationCode}

The authorization code to be validated and processed for granting access\.

#### Returns
[System\.Threading\.Tasks\.Task&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')[Abblix\.Utils\.Result&lt;](https://learn.microsoft.com/en-us/dotnet/api/abblix.utils.result-2 'Abblix\.Utils\.Result\`2')[AuthorizedGrant](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Endpoints.Token.Interfaces.AuthorizedGrant 'Abblix\.Oidc\.Server\.Endpoints\.Token\.Interfaces\.AuthorizedGrant')[,](https://learn.microsoft.com/en-us/dotnet/api/abblix.utils.result-2 'Abblix\.Utils\.Result\`2')[OidcError](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Common.OidcError 'Abblix\.Oidc\.Server\.Common\.OidcError')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/abblix.utils.result-2 'Abblix\.Utils\.Result\`2')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')  
A task that asynchronously returns a [Abblix\.Utils\.Result&lt;&gt;](https://learn.microsoft.com/en-us/dotnet/api/abblix.utils.result-2 'Abblix\.Utils\.Result\`2') representing the outcome
            of the authorization process, including any access tokens or refresh tokens issued as part of the grant\.

## IAuthorizationCodeService\.GenerateAuthorizationCodeAsync\(AuthorizedGrant, TimeSpan\) Method {#Abblix.Oidc.Server.Features.Storages.IAuthorizationCodeService.GenerateAuthorizationCodeAsync(Abblix.Oidc.Server.Endpoints.Token.Interfaces.AuthorizedGrant,System.TimeSpan)}

Generates a unique authorization code for a given authorization grant result and specified expiration time\.
The authorization code is a temporary code that the client exchanges for an access token, typically after
the user has authenticated and authorized the request\.

```csharp
System.Threading.Tasks.Task<string> GenerateAuthorizationCodeAsync(Abblix.Oidc.Server.Endpoints.Token.Interfaces.AuthorizedGrant authorizedGrant, System.TimeSpan authorizationCodeExpiresIn);
```
#### Parameters

###### `authorizedGrant` [AuthorizedGrant](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Endpoints.Token.Interfaces.AuthorizedGrant 'Abblix\.Oidc\.Server\.Endpoints\.Token\.Interfaces\.AuthorizedGrant') {#Abblix.Oidc.Server.Features.Storages.IAuthorizationCodeService.GenerateAuthorizationCodeAsync(Abblix.Oidc.Server.Endpoints.Token.Interfaces.AuthorizedGrant,System.TimeSpan).authorizedGrant}

An object encapsulating the result of the authorization grant, including
            user authentication session and authorization context details\.

###### `authorizationCodeExpiresIn` [System\.TimeSpan](https://learn.microsoft.com/en-us/dotnet/api/system.timespan 'System\.TimeSpan') {#Abblix.Oidc.Server.Features.Storages.IAuthorizationCodeService.GenerateAuthorizationCodeAsync(Abblix.Oidc.Server.Endpoints.Token.Interfaces.AuthorizedGrant,System.TimeSpan).authorizationCodeExpiresIn}

The duration after which the generated authorization code will expire\.

#### 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\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')  
A task that asynchronously returns the generated authorization code as a string\. This code
            is intended for single\-use and has a limited lifetime, after which it must be exchanged for an access token
            or considered invalid\.

## IAuthorizationCodeService\.RemoveAuthorizationCodeAsync\(string\) Method {#Abblix.Oidc.Server.Features.Storages.IAuthorizationCodeService.RemoveAuthorizationCodeAsync(string)}

Atomically removes an authorization code from storage and returns the grant it held, in a
single get\-and\-remove operation\. This is how a code is claimed for redemption: it enforces
the single\-use guarantee against a race between two simultaneous redemptions of the same
code \(RFC 6749 §4\.1\.2\) — exactly one caller wins and receives the grant, every other caller
finds the code already gone and receives an `invalid_grant` failure\.

```csharp
System.Threading.Tasks.Task<Abblix.Utils.Result<Abblix.Oidc.Server.Endpoints.Token.Interfaces.AuthorizedGrant,Abblix.Oidc.Server.Common.OidcError>> RemoveAuthorizationCodeAsync(string authorizationCode);
```
#### Parameters

###### `authorizationCode` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Features.Storages.IAuthorizationCodeService.RemoveAuthorizationCodeAsync(string).authorizationCode}

The authorization code to remove and claim\.

#### Returns
[System\.Threading\.Tasks\.Task&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')[Abblix\.Utils\.Result&lt;](https://learn.microsoft.com/en-us/dotnet/api/abblix.utils.result-2 'Abblix\.Utils\.Result\`2')[AuthorizedGrant](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Endpoints.Token.Interfaces.AuthorizedGrant 'Abblix\.Oidc\.Server\.Endpoints\.Token\.Interfaces\.AuthorizedGrant')[,](https://learn.microsoft.com/en-us/dotnet/api/abblix.utils.result-2 'Abblix\.Utils\.Result\`2')[OidcError](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Common.OidcError 'Abblix\.Oidc\.Server\.Common\.OidcError')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/abblix.utils.result-2 'Abblix\.Utils\.Result\`2')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')  
The grant on success when this caller won the claim; an `invalid_grant`[OidcError](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Common.OidcError 'Abblix\.Oidc\.Server\.Common\.OidcError') when the code is absent — already claimed by a concurrent request,
already consumed, expired, or never issued\.

### Remarks
A successfully claimed grant whose `IssuedTokens` is non\-empty indicates the code was
already used to issue tokens \(a sequential reuse\), which the caller treats as a reuse to be
rejected and whose tokens are revoked\.

## IAuthorizationCodeService\.UpdateAuthorizationGrantAsync\(string, AuthorizedGrant, TimeSpan\) Method {#Abblix.Oidc.Server.Features.Storages.IAuthorizationCodeService.UpdateAuthorizationGrantAsync(string,Abblix.Oidc.Server.Endpoints.Token.Interfaces.AuthorizedGrant,System.TimeSpan)}

Updates the authorization grant result based on a specific authorization code and expiration time\.
This method allows the authorization grant to be updated with new information or tokens as needed\.

```csharp
System.Threading.Tasks.Task UpdateAuthorizationGrantAsync(string authorizationCode, Abblix.Oidc.Server.Endpoints.Token.Interfaces.AuthorizedGrant authorizedGrant, System.TimeSpan authorizationCodeExpiresIn);
```
#### Parameters

###### `authorizationCode` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Features.Storages.IAuthorizationCodeService.UpdateAuthorizationGrantAsync(string,Abblix.Oidc.Server.Endpoints.Token.Interfaces.AuthorizedGrant,System.TimeSpan).authorizationCode}

The authorization code associated with the grant result to update\.

###### `authorizedGrant` [AuthorizedGrant](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Endpoints.Token.Interfaces.AuthorizedGrant 'Abblix\.Oidc\.Server\.Endpoints\.Token\.Interfaces\.AuthorizedGrant') {#Abblix.Oidc.Server.Features.Storages.IAuthorizationCodeService.UpdateAuthorizationGrantAsync(string,Abblix.Oidc.Server.Endpoints.Token.Interfaces.AuthorizedGrant,System.TimeSpan).authorizedGrant}

The updated authorization grant result containing the latest
            authentication and authorization details\.

###### `authorizationCodeExpiresIn` [System\.TimeSpan](https://learn.microsoft.com/en-us/dotnet/api/system.timespan 'System\.TimeSpan') {#Abblix.Oidc.Server.Features.Storages.IAuthorizationCodeService.UpdateAuthorizationGrantAsync(string,Abblix.Oidc.Server.Endpoints.Token.Interfaces.AuthorizedGrant,System.TimeSpan).authorizationCodeExpiresIn}

The duration after which the updated authorization code will expire\.

#### Returns
[System\.Threading\.Tasks\.Task](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task 'System\.Threading\.Tasks\.Task')  
A task representing the asynchronous operation of updating the authorization grant result\.
