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

## RefreshTokenService Class

Manages refresh tokens, key components in OAuth 2\.0 for extending authentication sessions without requiring
user re\-authentication\. This service handles the creation and validation of refresh tokens, supporting seamless
and secure user experiences by allowing access tokens to be renewed based on long\-lived refresh tokens\.

```csharp
public class RefreshTokenService : Abblix.Oidc.Server.Features.Tokens.IRefreshTokenService
```

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

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

## RefreshTokenService\(IIssuerProvider, TimeProvider, ITokenIdGenerator, IGrantIdGenerator, IAuthServiceJwtFormatter, ITokenRegistry\) Constructor {#Abblix.Oidc.Server.Features.Tokens.RefreshTokenService.RefreshTokenService(Abblix.Oidc.Server.Features.Issuer.IIssuerProvider,System.TimeProvider,Abblix.Oidc.Server.Features.RandomGenerators.ITokenIdGenerator,Abblix.Oidc.Server.Features.RandomGenerators.IGrantIdGenerator,Abblix.Oidc.Server.Features.Tokens.Formatters.IAuthServiceJwtFormatter,Abblix.Oidc.Server.Features.Storages.ITokenRegistry)}

Manages refresh tokens, key components in OAuth 2\.0 for extending authentication sessions without requiring
user re\-authentication\. This service handles the creation and validation of refresh tokens, supporting seamless
and secure user experiences by allowing access tokens to be renewed based on long\-lived refresh tokens\.

```csharp
public RefreshTokenService(Abblix.Oidc.Server.Features.Issuer.IIssuerProvider issuerProvider, System.TimeProvider clock, Abblix.Oidc.Server.Features.RandomGenerators.ITokenIdGenerator tokenIdGenerator, Abblix.Oidc.Server.Features.RandomGenerators.IGrantIdGenerator grantIdGenerator, Abblix.Oidc.Server.Features.Tokens.Formatters.IAuthServiceJwtFormatter jwtFormatter, Abblix.Oidc.Server.Features.Storages.ITokenRegistry tokenRegistry);
```
#### Parameters

###### `issuerProvider` [IIssuerProvider](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.Issuer.IIssuerProvider 'Abblix\.Oidc\.Server\.Features\.Issuer\.IIssuerProvider') {#Abblix.Oidc.Server.Features.Tokens.RefreshTokenService.RefreshTokenService(Abblix.Oidc.Server.Features.Issuer.IIssuerProvider,System.TimeProvider,Abblix.Oidc.Server.Features.RandomGenerators.ITokenIdGenerator,Abblix.Oidc.Server.Features.RandomGenerators.IGrantIdGenerator,Abblix.Oidc.Server.Features.Tokens.Formatters.IAuthServiceJwtFormatter,Abblix.Oidc.Server.Features.Storages.ITokenRegistry).issuerProvider}

Provider for the issuer claim in tokens\.

###### `clock` [System\.TimeProvider](https://learn.microsoft.com/en-us/dotnet/api/system.timeprovider 'System\.TimeProvider') {#Abblix.Oidc.Server.Features.Tokens.RefreshTokenService.RefreshTokenService(Abblix.Oidc.Server.Features.Issuer.IIssuerProvider,System.TimeProvider,Abblix.Oidc.Server.Features.RandomGenerators.ITokenIdGenerator,Abblix.Oidc.Server.Features.RandomGenerators.IGrantIdGenerator,Abblix.Oidc.Server.Features.Tokens.Formatters.IAuthServiceJwtFormatter,Abblix.Oidc.Server.Features.Storages.ITokenRegistry).clock}

Time provider for token timestamps\.

###### `tokenIdGenerator` [ITokenIdGenerator](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.RandomGenerators.ITokenIdGenerator 'Abblix\.Oidc\.Server\.Features\.RandomGenerators\.ITokenIdGenerator') {#Abblix.Oidc.Server.Features.Tokens.RefreshTokenService.RefreshTokenService(Abblix.Oidc.Server.Features.Issuer.IIssuerProvider,System.TimeProvider,Abblix.Oidc.Server.Features.RandomGenerators.ITokenIdGenerator,Abblix.Oidc.Server.Features.RandomGenerators.IGrantIdGenerator,Abblix.Oidc.Server.Features.Tokens.Formatters.IAuthServiceJwtFormatter,Abblix.Oidc.Server.Features.Storages.ITokenRegistry).tokenIdGenerator}

Generator for unique token identifiers\.

###### `grantIdGenerator` [IGrantIdGenerator](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.RandomGenerators.IGrantIdGenerator 'Abblix\.Oidc\.Server\.Features\.RandomGenerators\.IGrantIdGenerator') {#Abblix.Oidc.Server.Features.Tokens.RefreshTokenService.RefreshTokenService(Abblix.Oidc.Server.Features.Issuer.IIssuerProvider,System.TimeProvider,Abblix.Oidc.Server.Features.RandomGenerators.ITokenIdGenerator,Abblix.Oidc.Server.Features.RandomGenerators.IGrantIdGenerator,Abblix.Oidc.Server.Features.Tokens.Formatters.IAuthServiceJwtFormatter,Abblix.Oidc.Server.Features.Storages.ITokenRegistry).grantIdGenerator}

Generator for unique refresh\-token grant identifiers\.

###### `jwtFormatter` [IAuthServiceJwtFormatter](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.Tokens.Formatters.IAuthServiceJwtFormatter 'Abblix\.Oidc\.Server\.Features\.Tokens\.Formatters\.IAuthServiceJwtFormatter') {#Abblix.Oidc.Server.Features.Tokens.RefreshTokenService.RefreshTokenService(Abblix.Oidc.Server.Features.Issuer.IIssuerProvider,System.TimeProvider,Abblix.Oidc.Server.Features.RandomGenerators.ITokenIdGenerator,Abblix.Oidc.Server.Features.RandomGenerators.IGrantIdGenerator,Abblix.Oidc.Server.Features.Tokens.Formatters.IAuthServiceJwtFormatter,Abblix.Oidc.Server.Features.Storages.ITokenRegistry).jwtFormatter}

Formatter for encoding JWTs\.

###### `tokenRegistry` [ITokenRegistry](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.Storages.ITokenRegistry 'Abblix\.Oidc\.Server\.Features\.Storages\.ITokenRegistry') {#Abblix.Oidc.Server.Features.Tokens.RefreshTokenService.RefreshTokenService(Abblix.Oidc.Server.Features.Issuer.IIssuerProvider,System.TimeProvider,Abblix.Oidc.Server.Features.RandomGenerators.ITokenIdGenerator,Abblix.Oidc.Server.Features.RandomGenerators.IGrantIdGenerator,Abblix.Oidc.Server.Features.Tokens.Formatters.IAuthServiceJwtFormatter,Abblix.Oidc.Server.Features.Storages.ITokenRegistry).tokenRegistry}

Registry for tracking token status\.
### Methods

## RefreshTokenService\.AuthorizeByRefreshTokenAsync\(JsonWebToken\) Method {#Abblix.Oidc.Server.Features.Tokens.RefreshTokenService.AuthorizeByRefreshTokenAsync(Abblix.Jwt.JsonWebToken)}

Validates and authorizes a provided refresh token, reconstructing the user's authentication session and
authorization context\. This method facilitates continued access by validating the refresh token's integrity
and expiry, granting a new access token for continued use\.

```csharp
public System.Threading.Tasks.Task<Abblix.Utils.Result<Abblix.Oidc.Server.Endpoints.Token.Interfaces.AuthorizedGrant,Abblix.Oidc.Server.Common.OidcError>> AuthorizeByRefreshTokenAsync(Abblix.Jwt.JsonWebToken refreshToken);
```
#### Parameters

###### `refreshToken` [JsonWebToken](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt.JsonWebToken 'Abblix\.Jwt\.JsonWebToken') {#Abblix.Oidc.Server.Features.Tokens.RefreshTokenService.AuthorizeByRefreshTokenAsync(Abblix.Jwt.JsonWebToken).refreshToken}

The refresh token to be validated and authorized\.

Implements [AuthorizeByRefreshTokenAsync\(JsonWebToken\)](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.Tokens.IRefreshTokenService#Abblix.Oidc.Server.Features.Tokens.IRefreshTokenService.AuthorizeByRefreshTokenAsync(Abblix.Jwt.JsonWebToken) 'Abblix\.Oidc\.Server\.Features\.Tokens\.IRefreshTokenService\.AuthorizeByRefreshTokenAsync\(Abblix\.Jwt\.JsonWebToken\)')

#### 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, upon successful validation, results in an [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')
            encapsulating the reconstituted authentication session and authorization context\.

## RefreshTokenService\.CreateRefreshTokenAsync\(AuthSession, AuthorizationContext, ClientInfo, JsonWebToken\) Method {#Abblix.Oidc.Server.Features.Tokens.RefreshTokenService.CreateRefreshTokenAsync(Abblix.Oidc.Server.Features.UserAuthentication.AuthSession,Abblix.Oidc.Server.Common.AuthorizationContext,Abblix.Oidc.Server.Features.ClientInformation.ClientInfo,Abblix.Jwt.JsonWebToken)}

Generates a new refresh token based on the user's current authentication session and authorization context,
optionally renewing an existing refresh token\. This facilitates prolonged access without re\-authentication,
adhering to specified client policies for token expiration and renewal\.

```csharp
public System.Threading.Tasks.Task<Abblix.Oidc.Server.Features.Tokens.EncodedJsonWebToken?> CreateRefreshTokenAsync(Abblix.Oidc.Server.Features.UserAuthentication.AuthSession authSession, Abblix.Oidc.Server.Common.AuthorizationContext authContext, Abblix.Oidc.Server.Features.ClientInformation.ClientInfo clientInfo, Abblix.Jwt.JsonWebToken? refreshToken);
```
#### Parameters

###### `authSession` [AuthSession](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.UserAuthentication.AuthSession 'Abblix\.Oidc\.Server\.Features\.UserAuthentication\.AuthSession') {#Abblix.Oidc.Server.Features.Tokens.RefreshTokenService.CreateRefreshTokenAsync(Abblix.Oidc.Server.Features.UserAuthentication.AuthSession,Abblix.Oidc.Server.Common.AuthorizationContext,Abblix.Oidc.Server.Features.ClientInformation.ClientInfo,Abblix.Jwt.JsonWebToken).authSession}

The session details of the authenticated user, providing context for token issuance\.

###### `authContext` [AuthorizationContext](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Common.AuthorizationContext 'Abblix\.Oidc\.Server\.Common\.AuthorizationContext') {#Abblix.Oidc.Server.Features.Tokens.RefreshTokenService.CreateRefreshTokenAsync(Abblix.Oidc.Server.Features.UserAuthentication.AuthSession,Abblix.Oidc.Server.Common.AuthorizationContext,Abblix.Oidc.Server.Features.ClientInformation.ClientInfo,Abblix.Jwt.JsonWebToken).authContext}

Contextual information from the authorization process, including scopes and
            client\-specific settings\.

###### `clientInfo` [ClientInfo](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.ClientInformation.ClientInfo 'Abblix\.Oidc\.Server\.Features\.ClientInformation\.ClientInfo') {#Abblix.Oidc.Server.Features.Tokens.RefreshTokenService.CreateRefreshTokenAsync(Abblix.Oidc.Server.Features.UserAuthentication.AuthSession,Abblix.Oidc.Server.Common.AuthorizationContext,Abblix.Oidc.Server.Features.ClientInformation.ClientInfo,Abblix.Jwt.JsonWebToken).clientInfo}

Details of the client application requesting the token, used to apply appropriate
            token policies\.

###### `refreshToken` [JsonWebToken](https://www.abblix.com/en/docs/api/abblix-jwt/Abblix.Jwt.JsonWebToken 'Abblix\.Jwt\.JsonWebToken') {#Abblix.Oidc.Server.Features.Tokens.RefreshTokenService.CreateRefreshTokenAsync(Abblix.Oidc.Server.Features.UserAuthentication.AuthSession,Abblix.Oidc.Server.Common.AuthorizationContext,Abblix.Oidc.Server.Features.ClientInformation.ClientInfo,Abblix.Jwt.JsonWebToken).refreshToken}

An existing refresh token to be renewed, if applicable\. A new token is created
            if this is null or expired\.

Implements [CreateRefreshTokenAsync\(AuthSession, AuthorizationContext, ClientInfo, JsonWebToken\)](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.Tokens.IRefreshTokenService#Abblix.Oidc.Server.Features.Tokens.IRefreshTokenService.CreateRefreshTokenAsync(Abblix.Oidc.Server.Features.UserAuthentication.AuthSession,Abblix.Oidc.Server.Common.AuthorizationContext,Abblix.Oidc.Server.Features.ClientInformation.ClientInfo,Abblix.Jwt.JsonWebToken) 'Abblix\.Oidc\.Server\.Features\.Tokens\.IRefreshTokenService\.CreateRefreshTokenAsync\(Abblix\.Oidc\.Server\.Features\.UserAuthentication\.AuthSession, Abblix\.Oidc\.Server\.Common\.AuthorizationContext, Abblix\.Oidc\.Server\.Features\.ClientInformation\.ClientInfo, Abblix\.Jwt\.JsonWebToken\)')

#### Returns
[System\.Threading\.Tasks\.Task&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')[EncodedJsonWebToken](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.Tokens.EncodedJsonWebToken 'Abblix\.Oidc\.Server\.Features\.Tokens\.EncodedJsonWebToken')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')  
A task that results in a new or renewed [EncodedJsonWebToken](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.Tokens.EncodedJsonWebToken 'Abblix\.Oidc\.Server\.Features\.Tokens\.EncodedJsonWebToken') representing
            the refresh token, or null if the existing token cannot be renewed due to policy constraints or expiration\.
