refresh token generation added
This commit is contained in:
@@ -33,8 +33,9 @@ public class AuthPasswordHandler : IRequestHandler<AuthPasswordCommand, AuthPass
|
||||
return AuthPasswordResult.Failure();
|
||||
}
|
||||
|
||||
string refreshToken = await _tokenGenerator.GenerateRefreshTokenAsync(account, request.RememberMe);
|
||||
string accessToken = _tokenGenerator.GenerateAccessToken(account);
|
||||
|
||||
return null;
|
||||
return AuthPasswordResult.Success(refreshToken, accessToken);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user