refresh token generation added

This commit is contained in:
2026-02-02 20:34:29 +01:00
Unverified
parent dc12ee75e5
commit ffa2d68a64
4 changed files with 25 additions and 5 deletions

View File

@@ -5,6 +5,6 @@ namespace TimetableDesigner.Backend.Services.Authentication.Core.Helpers;
public interface ITokenGenerator
{
string GenerateAccessToken(Account account);
Task<string> GenerateRefreshTokenAsync(Account account);
Task<string> GenerateRefreshTokenAsync(Account account, bool isExtendable);
Task<string> ExtendRefreshTokenAsync();
}

View File

@@ -56,9 +56,28 @@ public class TokenGenerator : ITokenGenerator
return handler.WriteToken(token);
}
public async Task<string> GenerateRefreshTokenAsync(Account account)
public async Task<string> GenerateRefreshTokenAsync(Account account, bool isExtendable)
{
return null;
string lifetimeSection = isExtendable ? "Extended" : "Normal";
int lifetime = _configuration.GetSection("Tokens")
.GetSection("RefreshToken")
.GetSection("Lifetime")
.GetValue<int>(lifetimeSection);
Guid guid = Guid.NewGuid();
DateTimeOffset expirationDate = DateTimeOffset.UtcNow.AddMinutes(lifetime);
RefreshToken refreshToken = new RefreshToken
{
Token = guid,
ExpirationDate = expirationDate,
IsExtendable = isExtendable,
AccountId = account.Id,
};
await _databaseContext.RefreshTokens.AddAsync(refreshToken);
await _databaseContext.SaveChangesAsync();
return guid.ToString();
}
public async Task<string> ExtendRefreshTokenAsync()