mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-06 23:34:13 +02:00
Refactor classes to use constructor injection for dependencies
- Updated IrcBroadcaster to use constructor injection for IrcGatewayService. - Refactored JwtTokenService to initialize configuration values in the constructor. - Modified AuthController to use constructor injection for EchoHubDbContext and JwtTokenService. - Refactored ChannelsController to utilize constructor injection for dependencies. - Updated FilesController to use constructor injection for FileStorageService. - Refactored ServerController to initialize EchoHubDbContext and IConfiguration via constructor. - Modified UsersController to use constructor injection for EchoHubDbContext and ImageToAsciiService. - Updated EchoHubDbContext to use constructor for DbContextOptions. - Refactored ChatHub to use constructor injection for IChatService and ILogger. - Modified ChatService to utilize constructor injection for dependencies. - Refactored ServerDirectoryService to use constructor injection for IConfiguration, PresenceTracker, and ILogger.
This commit is contained in:
@@ -7,18 +7,25 @@ using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
namespace EchoHub.Server.Auth;
|
||||
|
||||
public class JwtTokenService(IConfiguration configuration)
|
||||
public class JwtTokenService
|
||||
{
|
||||
private readonly string _secret = configuration["Jwt:Secret"]
|
||||
?? throw new InvalidOperationException("Jwt:Secret is not configured.");
|
||||
private readonly string _issuer = configuration["Jwt:Issuer"]
|
||||
?? throw new InvalidOperationException("Jwt:Issuer is not configured.");
|
||||
private readonly string _audience = configuration["Jwt:Audience"]
|
||||
?? throw new InvalidOperationException("Jwt:Audience is not configured.");
|
||||
private readonly string _secret;
|
||||
private readonly string _issuer;
|
||||
private readonly string _audience;
|
||||
|
||||
private static readonly TimeSpan AccessTokenLifetime = TimeSpan.FromMinutes(15);
|
||||
public static readonly TimeSpan RefreshTokenLifetime = TimeSpan.FromDays(30);
|
||||
|
||||
public JwtTokenService(IConfiguration configuration)
|
||||
{
|
||||
_secret = configuration["Jwt:Secret"]
|
||||
?? throw new InvalidOperationException("Jwt:Secret is not configured.");
|
||||
_issuer = configuration["Jwt:Issuer"]
|
||||
?? throw new InvalidOperationException("Jwt:Issuer is not configured.");
|
||||
_audience = configuration["Jwt:Audience"]
|
||||
?? throw new InvalidOperationException("Jwt:Audience is not configured.");
|
||||
}
|
||||
|
||||
public (string Token, DateTimeOffset ExpiresAt) GenerateAccessToken(User user)
|
||||
{
|
||||
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_secret));
|
||||
|
||||
Reference in New Issue
Block a user