Вытащил солюшен на уровень выше, чтобы прощё было дотнетить
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is failing
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	continuous-integration/drone/push Build is failing
				
			This commit is contained in:
		
							
								
								
									
										34
									
								
								Infrastructure/Auth/TokenGenerator.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								Infrastructure/Auth/TokenGenerator.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| using System.IdentityModel.Tokens.Jwt; | ||||
| using System.Security.Claims; | ||||
| using ApplicationLayer.InfrastructureServicesInterfaces; | ||||
| using ApplicationLayer.Services.AuthServices.Common; | ||||
| using Domains.Users; | ||||
|  | ||||
| namespace Infrastructure.Auth; | ||||
|  | ||||
| /// <inheritdoc cref="ITokenGenerator"/> | ||||
| /// <param name="options">options kind of one in authorization registration in DI methods</param> | ||||
| /// <param name="tokenHandler">token handler</param> | ||||
| /// <param name="dateTimeProvider">date time provider</param> | ||||
| public class TokenGenerator(TokenGeneratorOptions options, JwtSecurityTokenHandler tokenHandler, IDateTimeProvider dateTimeProvider) | ||||
|     : ITokenGenerator | ||||
| { | ||||
|     /// <inheritdoc cref="ITokenGenerator.CreateToken"/> | ||||
|     public AuthToken CreateToken(User user) | ||||
|     { | ||||
|         var claims = new List<Claim> | ||||
|         { | ||||
|             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); | ||||
|  | ||||
|         return new AuthToken { Token = tokenHandler.WriteToken(token) }; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user