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

## TokenHandler Class

Manages the processing of token requests according to OAuth 2\.0 and OpenID Connect specifications\.
This includes validating the request for compliance with the protocol requirements and processing it to issue,
renew or exchange tokens as appropriate\.

```csharp
public class TokenHandler : Abblix.Oidc.Server.Endpoints.Token.Interfaces.ITokenHandler
```

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

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

## TokenHandler\(ITokenRequestValidator, ITokenRequestProcessor\) Constructor {#Abblix.Oidc.Server.Endpoints.Token.TokenHandler.TokenHandler(Abblix.Oidc.Server.Endpoints.Token.Interfaces.ITokenRequestValidator,Abblix.Oidc.Server.Endpoints.Token.Interfaces.ITokenRequestProcessor)}

Manages the processing of token requests according to OAuth 2\.0 and OpenID Connect specifications\.
This includes validating the request for compliance with the protocol requirements and processing it to issue,
renew or exchange tokens as appropriate\.

```csharp
public TokenHandler(Abblix.Oidc.Server.Endpoints.Token.Interfaces.ITokenRequestValidator validator, Abblix.Oidc.Server.Endpoints.Token.Interfaces.ITokenRequestProcessor processor);
```
#### Parameters

###### `validator` [ITokenRequestValidator](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Endpoints.Token.Interfaces.ITokenRequestValidator 'Abblix\.Oidc\.Server\.Endpoints\.Token\.Interfaces\.ITokenRequestValidator') {#Abblix.Oidc.Server.Endpoints.Token.TokenHandler.TokenHandler(Abblix.Oidc.Server.Endpoints.Token.Interfaces.ITokenRequestValidator,Abblix.Oidc.Server.Endpoints.Token.Interfaces.ITokenRequestProcessor).validator}

An implementation of [ITokenRequestValidator](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Endpoints.Token.Interfaces.ITokenRequestValidator 'Abblix\.Oidc\.Server\.Endpoints\.Token\.Interfaces\.ITokenRequestValidator') responsible for ensuring
            that token requests meet the required validation criteria\.

###### `processor` [ITokenRequestProcessor](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Endpoints.Token.Interfaces.ITokenRequestProcessor 'Abblix\.Oidc\.Server\.Endpoints\.Token\.Interfaces\.ITokenRequestProcessor') {#Abblix.Oidc.Server.Endpoints.Token.TokenHandler.TokenHandler(Abblix.Oidc.Server.Endpoints.Token.Interfaces.ITokenRequestValidator,Abblix.Oidc.Server.Endpoints.Token.Interfaces.ITokenRequestProcessor).processor}

An implementation of [ITokenRequestProcessor](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Endpoints.Token.Interfaces.ITokenRequestProcessor 'Abblix\.Oidc\.Server\.Endpoints\.Token\.Interfaces\.ITokenRequestProcessor') responsible for executing
            the logic necessary to issue, renew, or exchange tokens based on validated requests\.
### Methods

## TokenHandler\.HandleAsync\(TokenRequest, ClientRequest\) Method {#Abblix.Oidc.Server.Endpoints.Token.TokenHandler.HandleAsync(Abblix.Oidc.Server.Model.TokenRequest,Abblix.Oidc.Server.Model.ClientRequest)}

Asynchronously handles a token request by first validating it and then, if the validation is successful,
processing the request to issue, renew, or exchange tokens as required by the request parameters\.

```csharp
public System.Threading.Tasks.Task<Abblix.Utils.Result<Abblix.Oidc.Server.Endpoints.Token.Interfaces.TokenIssued,Abblix.Oidc.Server.Common.OidcError>> HandleAsync(Abblix.Oidc.Server.Model.TokenRequest tokenRequest, Abblix.Oidc.Server.Model.ClientRequest clientRequest);
```
#### Parameters

###### `tokenRequest` [TokenRequest](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Model.TokenRequest 'Abblix\.Oidc\.Server\.Model\.TokenRequest') {#Abblix.Oidc.Server.Endpoints.Token.TokenHandler.HandleAsync(Abblix.Oidc.Server.Model.TokenRequest,Abblix.Oidc.Server.Model.ClientRequest).tokenRequest}

An object containing the details of the token request, including the grant type,
            client credentials and other necessary parameters\.

###### `clientRequest` [ClientRequest](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Model.ClientRequest 'Abblix\.Oidc\.Server\.Model\.ClientRequest') {#Abblix.Oidc.Server.Endpoints.Token.TokenHandler.HandleAsync(Abblix.Oidc.Server.Model.TokenRequest,Abblix.Oidc.Server.Model.ClientRequest).clientRequest}

Additional information about the client making the request, used for contextual
            validation\.

Implements [HandleAsync\(TokenRequest, ClientRequest\)](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Endpoints.Token.Interfaces.ITokenHandler#Abblix.Oidc.Server.Endpoints.Token.Interfaces.ITokenHandler.HandleAsync(Abblix.Oidc.Server.Model.TokenRequest,Abblix.Oidc.Server.Model.ClientRequest) 'Abblix\.Oidc\.Server\.Endpoints\.Token\.Interfaces\.ITokenHandler\.HandleAsync\(Abblix\.Oidc\.Server\.Model\.TokenRequest, Abblix\.Oidc\.Server\.Model\.ClientRequest\)')

#### 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')[TokenIssued](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Endpoints.Token.Interfaces.TokenIssued 'Abblix\.Oidc\.Server\.Endpoints\.Token\.Interfaces\.TokenIssued')[,](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 [System\.Threading\.Tasks\.Task](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task 'System\.Threading\.Tasks\.Task') that resolves to a [TokenIssued](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Endpoints.Token.Interfaces.TokenIssued 'Abblix\.Oidc\.Server\.Endpoints\.Token\.Interfaces\.TokenIssued'), indicating the outcome of
the request handling\. The success response includes the issued tokens, while an [OidcError](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Common.OidcError 'Abblix\.Oidc\.Server\.Common\.OidcError')
details the reason for failure if the request does not pass validation or cannot be processed\.

### Remarks
This method is integral to the security and functionality of the OAuth 2\.0 and OpenID Connect framework,
ensuring that only valid and authorized requests result in the issuance, renewal, or exchange of tokens\.
It employs rigorous validation to prevent unauthorized access and to maintain the integrity of the token
lifecycle management process\.
