file-scoped namespaces
This commit is contained in:
		| @@ -3,12 +3,12 @@ using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using ApplicationLayer.Services.AuthServices.NeededServices; | ||||
| using Microsoft.Extensions.DependencyInjection; | ||||
|  | ||||
| namespace Infrastructure.Auth | ||||
| namespace Infrastructure.Auth; | ||||
|  | ||||
| public static class ServiceCollectionsExtensions | ||||
| { | ||||
|     public static class ServiceCollectionsExtensions | ||||
|     public static IServiceCollection AddTokenGenerator(this IServiceCollection services, TokenGeneratorOptions options) | ||||
|     { | ||||
|         public static IServiceCollection AddTokenGenerator(this IServiceCollection services, TokenGeneratorOptions options) | ||||
|         { | ||||
|             services.AddSingleton<JwtSecurityTokenHandler>(); | ||||
|             services.AddSingleton<ITokenGenerator, TokenGenerator>(provider => | ||||
|             { | ||||
| @@ -20,5 +20,4 @@ namespace Infrastructure.Auth | ||||
|  | ||||
|             return services; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -4,27 +4,26 @@ using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using ApplicationLayer.Services.AuthServices.NeededServices; | ||||
| using Domains.Users; | ||||
|  | ||||
| namespace Infrastructure.Auth | ||||
| namespace Infrastructure.Auth; | ||||
|  | ||||
| public class TokenGenerator(TokenGeneratorOptions options, JwtSecurityTokenHandler tokenHandler, IDateTimeProvider dateTimeProvider) | ||||
|     : ITokenGenerator | ||||
| { | ||||
|     public class TokenGenerator(TokenGeneratorOptions options, JwtSecurityTokenHandler tokenHandler, IDateTimeProvider dateTimeProvider) | ||||
|         : ITokenGenerator | ||||
|     public string CreateToken(User user) | ||||
|     { | ||||
|         public string CreateToken(User user) | ||||
|         var claims = new List<Claim> | ||||
|         { | ||||
|             var claims = new List<Claim> | ||||
|             { | ||||
|                 new(ClaimTypes.Role, user.Role.ToString()), | ||||
|                 new(ClaimTypes.NameIdentifier, user.Id.ToString()) | ||||
|             }; | ||||
|             new(ClaimTypes.Role, user.Role.ToString()), | ||||
|             new(ClaimTypes.NameIdentifier, user.Id.ToString()) | ||||
|         }; | ||||
|  | ||||
|             var token = new JwtSecurityToken( | ||||
|                 issuer: options.Issuer, | ||||
|                 audience: options.Audience, | ||||
|                 expires: dateTimeProvider.Now().Add(options.ValidTime), | ||||
|                 signingCredentials: options.Credentials, | ||||
|                 claims: claims); | ||||
|         var token = new JwtSecurityToken( | ||||
|             issuer: options.Issuer, | ||||
|             audience: options.Audience, | ||||
|             expires: dateTimeProvider.Now().Add(options.ValidTime), | ||||
|             signingCredentials: options.Credentials, | ||||
|             claims: claims); | ||||
|  | ||||
|             return tokenHandler.WriteToken(token); | ||||
|         } | ||||
|         return tokenHandler.WriteToken(token); | ||||
|     } | ||||
| } | ||||
| } | ||||
| @@ -1,6 +1,5 @@ | ||||
| using Microsoft.IdentityModel.Tokens; | ||||
|  | ||||
| namespace Infrastructure.Auth | ||||
| { | ||||
|     public record TokenGeneratorOptions(string Issuer, string Audience, TimeSpan ValidTime, SigningCredentials Credentials); | ||||
| } | ||||
| namespace Infrastructure.Auth; | ||||
|  | ||||
| public record TokenGeneratorOptions(string Issuer, string Audience, TimeSpan ValidTime, SigningCredentials Credentials); | ||||
		Reference in New Issue
	
	Block a user