| @@ -0,0 +1,11 @@ | |||
| using System.Security.Claims; | |||
| namespace BlackRock.Reporting.API.Authentication | |||
| { | |||
| public interface IJwtManager | |||
| { | |||
| string GenerateToken(string username, int expireMinutes = 20); | |||
| ClaimsPrincipal GetPrincipal(string token); | |||
| string GetUserName(string token); | |||
| } | |||
| } | |||
| @@ -0,0 +1,11 @@ | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| namespace BlackRock.Reporting.API.Authentication | |||
| { | |||
| public interface IRefreshTokenManager | |||
| { | |||
| Task<string> GenerateRefreshToken(ApplicationUser user); | |||
| Task RemoveRefreshToken(ApplicationUser user); | |||
| Task<bool> ValidateRefreshToken(ApplicationUser user, string refreshToken); | |||
| } | |||
| } | |||
| @@ -0,0 +1,105 @@ | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using Microsoft.AspNetCore.Identity; | |||
| using Microsoft.IdentityModel.Tokens; | |||
| using System.IdentityModel.Tokens.Jwt; | |||
| using System.Security.Claims; | |||
| namespace BlackRock.Reporting.API.Authentication | |||
| { | |||
| public class JwtManager : IJwtManager | |||
| { | |||
| //private string Secret = "db3OIsj+BXE9NZDy0t8W3TcNekrF+2d/1sFnWG4HnV8TZY30iTOdtVWJG8abWvB1GlOgJuQZdcF2Luqm/hccMw=="; | |||
| //private readonly IConfiguration configuration; | |||
| private readonly string Secret; | |||
| //public JwtManager(IConfiguration configuration) | |||
| //{ | |||
| // this.configuration = configuration; | |||
| // Secret = configuration["SecurityKey"]; | |||
| //} | |||
| public string GenerateToken(string username, int expireMinutes = 20) | |||
| { | |||
| expireMinutes = 1; | |||
| var symmetricKey = Convert.FromBase64String(Secret); | |||
| var tokenHandler = new JwtSecurityTokenHandler(); | |||
| var now = DateTime.UtcNow; | |||
| var tokenDescriptor = new SecurityTokenDescriptor | |||
| { | |||
| Subject = new ClaimsIdentity(new[] | |||
| { | |||
| new Claim(ClaimTypes.Name, username) | |||
| }), | |||
| Expires = now.AddMinutes(Convert.ToInt32(expireMinutes)), | |||
| SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(symmetricKey), SecurityAlgorithms.HmacSha256Signature) | |||
| }; | |||
| SecurityToken securityToken = tokenHandler.CreateToken(tokenDescriptor); | |||
| var token = tokenHandler.WriteToken(securityToken); | |||
| return token; | |||
| } | |||
| public string GetUserName(string token) | |||
| { | |||
| try | |||
| { | |||
| var tokenHandler = new JwtSecurityTokenHandler(); | |||
| var jwtToken = tokenHandler.ReadToken(token) as JwtSecurityToken; | |||
| if (jwtToken == null) | |||
| return null; | |||
| var symmetricKey = Convert.FromBase64String(Secret); | |||
| var validationParameters = new TokenValidationParameters() | |||
| { | |||
| ValidateIssuer = false, | |||
| ValidateAudience = false, | |||
| ValidateLifetime = false, | |||
| RequireExpirationTime = false, | |||
| IssuerSigningKey = new SymmetricSecurityKey(symmetricKey) | |||
| }; | |||
| SecurityToken validatedToken = new JwtSecurityToken(); | |||
| var principal = tokenHandler.ValidateToken(token, validationParameters, out validatedToken); | |||
| return principal.Identity.Name; | |||
| } | |||
| catch (Exception) | |||
| { | |||
| return null; | |||
| } | |||
| } | |||
| public ClaimsPrincipal GetPrincipal(string token) | |||
| { | |||
| try | |||
| { | |||
| var tokenHandler = new JwtSecurityTokenHandler(); | |||
| var jwtToken = tokenHandler.ReadToken(token) as JwtSecurityToken; | |||
| if (jwtToken == null) | |||
| return null; | |||
| var symmetricKey = Convert.FromBase64String(Secret); | |||
| var validationParameters = new TokenValidationParameters() | |||
| { | |||
| RequireExpirationTime = true, | |||
| ValidateIssuer = false, | |||
| ValidateLifetime = true, | |||
| ValidateAudience = false, | |||
| IssuerSigningKey = new SymmetricSecurityKey(symmetricKey) | |||
| }; | |||
| SecurityToken validatedToken = new JwtSecurityToken(); | |||
| var principal = tokenHandler.ValidateToken(token, validationParameters, out validatedToken); | |||
| return principal; | |||
| } | |||
| catch (Exception) | |||
| { | |||
| return null; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,41 @@ | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using Microsoft.AspNetCore.Identity; | |||
| namespace BlackRock.Reporting.API.Authentication | |||
| { | |||
| public class RefreshTokenManager : IRefreshTokenManager | |||
| { | |||
| private readonly UserManager<ApplicationUser> userManager; | |||
| public RefreshTokenManager(UserManager<ApplicationUser> userManager) | |||
| { | |||
| this.userManager = userManager; | |||
| } | |||
| public async Task<string> GenerateRefreshToken(ApplicationUser user) | |||
| { | |||
| var newRefreshToken = await userManager.GenerateUserTokenAsync(user, "MyApp", "RefreshToken"); | |||
| await userManager.SetAuthenticationTokenAsync(user, "MyApp", "RefreshToken", newRefreshToken); | |||
| var refreshToken = await userManager.GetAuthenticationTokenAsync(user, "MyApp", "RefreshToken"); | |||
| var isValid = await userManager.VerifyUserTokenAsync(user, "MyApp", "RefreshToken", refreshToken); | |||
| if (!isValid) | |||
| throw new UnauthorizedAccessException("Invalid token passed"); | |||
| return refreshToken; | |||
| } | |||
| public async Task RemoveRefreshToken(ApplicationUser user) | |||
| { | |||
| await userManager.RemoveAuthenticationTokenAsync(user, "MyApp", "RefreshToken"); | |||
| } | |||
| public async Task<bool> ValidateRefreshToken(ApplicationUser user, string refreshToken) | |||
| { | |||
| var refreshTokenFromDb = await userManager.GetAuthenticationTokenAsync(user, "MyApp", "RefreshToken"); | |||
| if(refreshTokenFromDb == null || refreshTokenFromDb != refreshToken) | |||
| throw new UnauthorizedAccessException("Invalid token passed"); | |||
| return true; | |||
| } | |||
| } | |||
| } | |||
| @@ -42,6 +42,10 @@ | |||
| <PackageReference Include="iTextSharp" Version="5.5.13.2" /> | |||
| <PackageReference Include="MediatR" Version="9.0.0" /> | |||
| <PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" /> | |||
| <PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.7" /> | |||
| <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.0" /> | |||
| <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.0" /> | |||
| <PackageReference Include="Microsoft.Build.Tasks.Core" Version="17.0.0" /> | |||
| <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" /> | |||
| <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" /> | |||
| <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" /> | |||
| @@ -0,0 +1,45 @@ | |||
| using BlackRock.Reporting.API.Mediator.AuthenticationMediator.Commands; | |||
| using BlackRock.Reporting.API.Mediator.AuthenticationMediator.Models; | |||
| using MediatR; | |||
| using Microsoft.AspNetCore.Mvc; | |||
| namespace BlackRock.Reporting.API.Controllers | |||
| { | |||
| public class AuthenticationController : ControllerBase | |||
| { | |||
| private readonly IMediator mediator; | |||
| public AuthenticationController(IMediator mediator) | |||
| { | |||
| this.mediator = mediator; | |||
| } | |||
| [HttpPost("login")] | |||
| public async Task<IActionResult> Login([FromBody] LoginCommand loginCommand) | |||
| { | |||
| var result = await mediator.Send(loginCommand); | |||
| if (!result.IsSuccess) | |||
| return Unauthorized(result.Error); | |||
| return Ok(result.Data); | |||
| } | |||
| [HttpPost("refresh")] | |||
| public async Task<IActionResult> Refresh([FromBody] RefreshCommand refreshCred) | |||
| { | |||
| var result = await mediator.Send(refreshCred); | |||
| if (!result.IsSuccess) | |||
| return Unauthorized(result.Error); | |||
| return Ok(result.Data); | |||
| } | |||
| [HttpPost("logout")] | |||
| public async Task<IActionResult> Logout([FromBody] LogoutCommand refreshCred) | |||
| { | |||
| var result = await mediator.Send(refreshCred); | |||
| if (!result.IsSuccess) | |||
| return Unauthorized(result.Error); | |||
| return Ok(); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,86 @@ | |||
| using Microsoft.AspNetCore.Mvc; | |||
| using BlackRock.Reporting.API.Mediator.DocumentMediator; | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using Microsoft.AspNetCore.Authorization; | |||
| using BlackRock.Reporting.API.Exceptions; | |||
| namespace BlackRock.Reporting.API.Controllers | |||
| { | |||
| //[Authorize] | |||
| [Route("api/[controller]")] | |||
| public class DocumentsController : ControllerBase | |||
| { | |||
| private readonly IDocumentMediator mediator; | |||
| public DocumentsController(IDocumentMediator mediator) | |||
| { | |||
| this.mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); | |||
| } | |||
| // GET: api/documents/Page=2&PageSize=25 | |||
| [HttpGet("{id}")] | |||
| public async Task<IActionResult> GetDocumentById(int id) | |||
| { | |||
| var result = await mediator.GetDocument(id); | |||
| if (!result.IsSuccess) | |||
| return BadRequest(); | |||
| if (result.Data == null) | |||
| return NotFound("Id is not valid"); | |||
| return Ok(result.Data); | |||
| } | |||
| // GET: api/documents | |||
| [HttpGet] | |||
| public async Task<IActionResult> GetDocuments(PaggingAndFiltering query) | |||
| { | |||
| throw new DomainException("Relay"); | |||
| var result = await mediator.GetDocuments(query); | |||
| if (!result.IsSuccess) | |||
| return BadRequest(); | |||
| if (result.Data == null) | |||
| return NotFound(); | |||
| return Ok(result.Data); | |||
| } | |||
| // POST: api/documents | |||
| [HttpPost] | |||
| public async Task<IActionResult> CreateDocument([FromBody] CreateDocumentForm form) | |||
| { | |||
| if (!ModelState.IsValid) | |||
| return BadRequest(ModelState); | |||
| var result = await mediator.CreateDocument(form); | |||
| if (!result.IsSuccess) | |||
| return BadRequest(result.Error); | |||
| return Ok(result.Data); | |||
| } | |||
| // PUT: api/documents/{id} | |||
| [HttpPut] | |||
| public async Task<IActionResult> UpdateDocument(int id, [FromBody] UpdateDocumentForm form) | |||
| { | |||
| if (!ModelState.IsValid) | |||
| return BadRequest(ModelState); | |||
| //form.Id = id; | |||
| var result = await mediator.UpdateDocument(form); | |||
| if (!result.IsSuccess) | |||
| return BadRequest(result.Error); | |||
| return Accepted(); | |||
| } | |||
| // DELETE: api/documents/{id} | |||
| [HttpDelete] | |||
| public async Task<IActionResult> DeleteDocument(int id) | |||
| { | |||
| var result = await mediator.DeleteDocument(id); | |||
| if (!result.IsSuccess) | |||
| return BadRequest(result.Error); | |||
| return NoContent(); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,13 +1,16 @@ | |||
| using BlackRock.Reporting.API.Controllers.Model; | |||
| using BlackRock.Reporting.API.Mediator.Commands; | |||
| using BlackRock.Reporting.API.Mediator.Queries; | |||
| using BlackRock.Reporting.API.Jwt.Filters; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Commands; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Queries; | |||
| using MediatR; | |||
| using Microsoft.AspNetCore.Authorization; | |||
| using Microsoft.AspNetCore.Mvc; | |||
| using BlackRock.Reporting.API.Mediator.Model; | |||
| namespace BlackRock.Reporting.API.Controllers | |||
| { | |||
| //[Route("api/users")] | |||
| [Authorize] | |||
| //[JwtAuthentication] | |||
| public class UsersController : Controller | |||
| { | |||
| private readonly IMediator mediator; | |||
| @@ -22,7 +25,7 @@ namespace BlackRock.Reporting.API.Controllers | |||
| [Route("api/users/{id}")] | |||
| public async Task<IActionResult> GetUser(int id) | |||
| { | |||
| var result = await mediator.Send(new GetUsersQuery(id)); | |||
| var result = await mediator.Send(new GetUserQuery { Id = id }); | |||
| if (!result.IsSuccess) | |||
| return BadRequest(result.Error); | |||
| @@ -42,7 +45,7 @@ namespace BlackRock.Reporting.API.Controllers | |||
| return BadRequest(result.Error); | |||
| if (result.Data == null) | |||
| return NotFound("Id is not valid"); | |||
| return NotFound(); | |||
| return Ok(result.Data); | |||
| @@ -50,7 +53,7 @@ namespace BlackRock.Reporting.API.Controllers | |||
| // POST: api/users | |||
| [HttpPost] | |||
| [Route("api/users")] | |||
| public async Task<IActionResult> CreateUser([FromBody] CreateUsersCommand user) | |||
| public async Task<IActionResult> CreateUser([FromBody] CreateUserCommand user) | |||
| { | |||
| if (!ModelState.IsValid) | |||
| return BadRequest(ModelState); | |||
| @@ -66,12 +69,12 @@ namespace BlackRock.Reporting.API.Controllers | |||
| // PUT: api/users/1 | |||
| [HttpPut] | |||
| [Route("api/users/{id}")] | |||
| public async Task<IActionResult> UpdateAllUser(int id, [FromBody] UserCommand user) | |||
| public async Task<IActionResult> UpdateUser(int id, [FromBody] UpdateUserCommand user) | |||
| { | |||
| if (!ModelState.IsValid) | |||
| return BadRequest(ErrorResponse.Validation(ModelState)); | |||
| var result = await mediator.Send(new UpdateAllUsersCommand(id,user)); | |||
| user.Id = id; | |||
| var result = await mediator.Send(user); | |||
| if (!result.IsSuccess) | |||
| return BadRequest(result.Error); | |||
| @@ -80,12 +83,13 @@ namespace BlackRock.Reporting.API.Controllers | |||
| // PATCH: api/users/1/email | |||
| [HttpPatch] | |||
| [Route("api/users/{id}/email")] | |||
| public async Task<IActionResult> UpdateUserEmail(int id, [FromBody] UserCommand user) | |||
| public async Task<IActionResult> UpdateUserEmail(int id, [FromBody] UpdateUserEmailCommand user) | |||
| { | |||
| if (!ModelState.IsValid) | |||
| return BadRequest(ErrorResponse.Validation(ModelState)); | |||
| var result = await mediator.Send(new UpdateEmailUsersCommand(id, user)); | |||
| user.Id = id; | |||
| var result = await mediator.Send(user); | |||
| if (!result.IsSuccess) | |||
| return BadRequest(result.Error); | |||
| @@ -99,7 +103,7 @@ namespace BlackRock.Reporting.API.Controllers | |||
| if (!ModelState.IsValid) | |||
| return BadRequest(ErrorResponse.Validation(ModelState)); | |||
| var result = await mediator.Send(new DeleteUsersCommand(id)); | |||
| var result = await mediator.Send(new DeleteUsersCommand { Id = id }); | |||
| if (!result.IsSuccess) | |||
| return BadRequest(result.Error); | |||
| @@ -0,0 +1,8 @@ | |||
| using Microsoft.AspNetCore.Identity; | |||
| namespace BlackRock.Reporting.API.Core.Models | |||
| { | |||
| public class ApplicationUser :IdentityUser | |||
| { | |||
| } | |||
| } | |||
| @@ -0,0 +1,38 @@ | |||
| using System.Net.Mime; | |||
| using System.Text.Json; | |||
| namespace BlackRock.Reporting.API.Exceptions | |||
| { | |||
| public class ApplicationExceptionMiddleware | |||
| { | |||
| private readonly RequestDelegate next; | |||
| private readonly IExceptionHandler exceptionHandler; | |||
| private readonly ILogger<ApplicationExceptionMiddleware> logger; | |||
| public ApplicationExceptionMiddleware(RequestDelegate next,IExceptionHandler exceptionHandler,ILogger<ApplicationExceptionMiddleware> logger) | |||
| { | |||
| this.next = next; | |||
| this.exceptionHandler = exceptionHandler; | |||
| this.logger = logger; | |||
| } | |||
| public async Task InvokeAsync(HttpContext httpContext) | |||
| { | |||
| try | |||
| { | |||
| await next(httpContext); | |||
| } | |||
| catch (Exception ex) | |||
| { | |||
| var error = exceptionHandler.HandleException(ex); | |||
| if(!httpContext.Response.HasStarted) | |||
| { | |||
| httpContext.Response.Clear(); | |||
| httpContext.Response.ContentType = MediaTypeNames.Application.Json; | |||
| httpContext.Response.StatusCode = (int)error.StatusCode; | |||
| await httpContext.Response.WriteAsync(JsonSerializer.Serialize(error)); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,69 @@ | |||
| using System.Net; | |||
| using System.Net.Mime; | |||
| using System.Text.Json; | |||
| namespace BlackRock.Reporting.API.Exceptions | |||
| { | |||
| public class ExceptionMiddleware | |||
| { | |||
| private readonly RequestDelegate _next; | |||
| private readonly ILoggingBuilder _logger; | |||
| public ExceptionMiddleware(RequestDelegate next, ILoggingBuilder logger) | |||
| { | |||
| _logger = logger; | |||
| _next = next; | |||
| } | |||
| public async Task InvokeAsync(HttpContext httpContext) | |||
| { | |||
| try | |||
| { | |||
| await _next(httpContext); | |||
| } | |||
| catch (Exception ex) | |||
| { | |||
| //_logger.LogError($"Something went wrong: {ex}"); | |||
| await HandleExceptionAsync(httpContext, ex); | |||
| } | |||
| } | |||
| private async Task HandleExceptionAsync(HttpContext context, Exception exception) | |||
| { | |||
| context.Response.ContentType = "application/json"; | |||
| context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; | |||
| await context.Response.WriteAsync(new Error() | |||
| { | |||
| StatusCode = (HttpStatusCode)context.Response.StatusCode, | |||
| Title = "Internal Server Error from the custom middleware." | |||
| }.ToString()); | |||
| } | |||
| } | |||
| public class ApplicationExceptionMiddlewareBase | |||
| { | |||
| private readonly RequestDelegate next; | |||
| private readonly IExceptionHandler exceptionHandler; | |||
| private readonly ILogger<ApplicationExceptionMiddleware> logger; | |||
| public ApplicationExceptionMiddlewareBase(RequestDelegate next, IExceptionHandler exceptionHandler, ILogger<ApplicationExceptionMiddleware> logger) | |||
| { | |||
| this.next = next; | |||
| this.exceptionHandler = exceptionHandler; | |||
| this.logger = logger; | |||
| } | |||
| public async Task InvokeAsync(HttpContext httpContext) | |||
| { | |||
| try | |||
| { | |||
| await next(httpContext); | |||
| } | |||
| catch (Exception ex) | |||
| { | |||
| var error = exceptionHandler.HandleException(ex); | |||
| if (!httpContext.Response.HasStarted) | |||
| { | |||
| httpContext.Response.Clear(); | |||
| httpContext.Response.ContentType = MediaTypeNames.Application.Json; | |||
| httpContext.Response.StatusCode = (int)error.StatusCode; | |||
| await httpContext.Response.WriteAsync(JsonSerializer.Serialize(error)); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,13 @@ | |||
| namespace BlackRock.Reporting.API.Exceptions | |||
| { | |||
| public class DomainException : Exception | |||
| { | |||
| public DomainException(string? message) : base(message) | |||
| { | |||
| } | |||
| public DomainException(string? message, Exception? innerException) : base(message, innerException) | |||
| { | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,15 @@ | |||
| using System.Net; | |||
| using System.Text.Json; | |||
| namespace BlackRock.Reporting.API.Exceptions | |||
| { | |||
| public class Error | |||
| { | |||
| public string Title { get; set; } | |||
| public HttpStatusCode StatusCode { get; set; } | |||
| public override string ToString() | |||
| { | |||
| return JsonSerializer.Serialize(this); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,59 @@ | |||
| using System.Net; | |||
| namespace BlackRock.Reporting.API.Exceptions | |||
| { | |||
| public class ExceptionHandler : IExceptionHandler | |||
| { | |||
| private readonly ILogger<ExceptionHandler> logger; | |||
| public ExceptionHandler(ILogger<ExceptionHandler> logger) | |||
| { | |||
| this.logger = logger; | |||
| } | |||
| public Error HandleException(Exception exception) | |||
| { | |||
| var error = exception switch | |||
| { | |||
| DomainException domainException => HandleDomainException(domainException), | |||
| ResourceNotFoundException resourceNotFoundException => HandleResourceNotFoundException(resourceNotFoundException) | |||
| }; | |||
| return error; | |||
| } | |||
| private Error HandleResourceNotFoundException(ResourceNotFoundException resourceNotFoundException) | |||
| { | |||
| logger.LogInformation(resourceNotFoundException, resourceNotFoundException.Message); | |||
| return | |||
| new Error | |||
| { | |||
| Title = resourceNotFoundException.Message, | |||
| StatusCode = HttpStatusCode.BadRequest | |||
| }; | |||
| } | |||
| private Error HandleDomainException(DomainException domainException) | |||
| { | |||
| logger.LogInformation(domainException, domainException.Message); | |||
| return | |||
| new Error | |||
| { | |||
| Title = domainException.Message, | |||
| StatusCode = HttpStatusCode.BadRequest | |||
| }; | |||
| } | |||
| private Error HandleUnhandledException(Exception exception) | |||
| { | |||
| logger.LogInformation(exception, exception.Message); | |||
| return | |||
| new Error | |||
| { | |||
| Title = exception.Message, | |||
| StatusCode = HttpStatusCode.InternalServerError | |||
| }; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,42 @@ | |||
| using System.Net; | |||
| namespace BlackRock.Reporting.API.Exceptions | |||
| { | |||
| public class BRExceptionMiddleware | |||
| { | |||
| private readonly RequestDelegate _next; | |||
| private readonly ILoggingBuilder _logger; | |||
| public BRExceptionMiddleware(RequestDelegate next, ILoggingBuilder logger) | |||
| { | |||
| _logger = logger; | |||
| _next = next; | |||
| } | |||
| public async Task InvokeAsync(HttpContext httpContext) | |||
| { | |||
| try | |||
| { | |||
| await _next(httpContext); | |||
| } | |||
| catch (Exception ex) | |||
| { | |||
| //_logger.LogError($"Something went wrong: {ex}"); | |||
| await HandleExceptionAsync(httpContext, ex); | |||
| } | |||
| } | |||
| private async Task HandleExceptionAsync(HttpContext context, Exception exception) | |||
| { | |||
| context.Response.ContentType = "application/json"; | |||
| context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; | |||
| var message = exception switch | |||
| { | |||
| DomainException => "Access violation error from the custom middleware", | |||
| _ => "Internal Server Error from the custom middleware." | |||
| }; | |||
| await context.Response.WriteAsync(new Error() | |||
| { | |||
| StatusCode = (HttpStatusCode)context.Response.StatusCode, | |||
| Title = message | |||
| }.ToString()); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,30 @@ | |||
| using Microsoft.AspNetCore.Diagnostics; | |||
| using System.Net; | |||
| namespace BlackRock.Reporting.API.Exceptions | |||
| { | |||
| public static class ExceptionMiddlewareExtensions | |||
| { | |||
| public static void ConfigureExceptionHandler(this IApplicationBuilder app, ILoggingBuilder logger) | |||
| { | |||
| app.UseExceptionHandler(appError => | |||
| { | |||
| appError.Run(async context => | |||
| { | |||
| context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; | |||
| context.Response.ContentType = "application/json"; | |||
| var contextFeature = context.Features.Get<IExceptionHandlerFeature>(); | |||
| if (contextFeature != null) | |||
| { | |||
| //logger.LogError($"Something went wrong: {contextFeature.Error}"); | |||
| await context.Response.WriteAsync(new Error() | |||
| { | |||
| StatusCode = (HttpStatusCode)context.Response.StatusCode, | |||
| Title = "Internal Server Error from Custom MiidleWare" | |||
| }.ToString()); | |||
| } | |||
| }); | |||
| }); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,8 @@ | |||
| namespace BlackRock.Reporting.API.Exceptions | |||
| { | |||
| public interface IExceptionHandler | |||
| { | |||
| public Error HandleException(Exception exception); | |||
| } | |||
| } | |||
| @@ -0,0 +1,13 @@ | |||
| namespace BlackRock.Reporting.API.Exceptions | |||
| { | |||
| public class ResourceNotFoundException : Exception | |||
| { | |||
| public ResourceNotFoundException(string? message) : base(message) | |||
| { | |||
| } | |||
| public ResourceNotFoundException(string? message, Exception? innerException) : base(message, innerException) | |||
| { | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,8 @@ | |||
| namespace BlackRock.Reporting.API.Jwt | |||
| { | |||
| public class AuthenticationResponse | |||
| { | |||
| public string JwtToken { get; set; } | |||
| public string RefreshToken { get; set; } | |||
| } | |||
| } | |||
| @@ -0,0 +1,59 @@ | |||
| using Microsoft.AspNetCore.Authentication; | |||
| using Microsoft.Extensions.Options; | |||
| using System.Security.Claims; | |||
| using System.Text.Encodings.Web; | |||
| namespace BlackRock.Reporting.API.Jwt | |||
| { | |||
| public class BasicAuthenticationOptions : AuthenticationSchemeOptions | |||
| { | |||
| } | |||
| public class CustomAuthenticationHandler : AuthenticationHandler<BasicAuthenticationOptions> | |||
| { | |||
| public CustomAuthenticationHandler(IOptionsMonitor<BasicAuthenticationOptions> options, | |||
| ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock) | |||
| { | |||
| } | |||
| protected override async Task<AuthenticateResult> HandleAuthenticateAsync() | |||
| { | |||
| //return AuthenticateResult.Success(new AuthenticationTicket | |||
| // Principal = new System.Security.Claims.ClaimsPrincipal(), | |||
| // AuthenticationScheme = Scheme.Name | |||
| //}); | |||
| if (!Request.Headers.ContainsKey("Authorization")) | |||
| return AuthenticateResult.Fail("unauthorized"); | |||
| string authorizationHeader = Request.Headers["Authorization"]; | |||
| if (string.IsNullOrEmpty(authorizationHeader)) | |||
| return AuthenticateResult.Fail("unauthorized"); | |||
| if (!authorizationHeader.StartsWith("bearer", StringComparison.OrdinalIgnoreCase)) | |||
| return AuthenticateResult.Fail("unauthorized"); | |||
| string token = authorizationHeader.Substring("bearer".Length).Trim(); | |||
| if (string.IsNullOrEmpty(token)) | |||
| return AuthenticateResult.Fail("unauthorized"); | |||
| try | |||
| { | |||
| return ValidateToken(token); | |||
| } | |||
| catch (Exception ex) | |||
| { | |||
| return AuthenticateResult.Fail("unauthorize"); | |||
| } | |||
| } | |||
| private AuthenticateResult ValidateToken(string token) | |||
| { | |||
| var principal = new ClaimsPrincipal();//JwtManager.GetPrincipal(token); | |||
| if (principal == null) | |||
| return AuthenticateResult.Fail("unauthorized"); | |||
| AuthenticationTicket ticket = new AuthenticationTicket(principal, Scheme.Name); | |||
| return AuthenticateResult.Success(ticket); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,35 @@ | |||
| using System.Net; | |||
| using System.Net.Http.Headers; | |||
| using System.Web.Http; | |||
| namespace BlackRock.Reporting.API.Jwt.Filters | |||
| { | |||
| public class AddChallengeOnUnauthorizedResult : IHttpActionResult | |||
| { | |||
| public AddChallengeOnUnauthorizedResult(AuthenticationHeaderValue challenge, IHttpActionResult innerResult) | |||
| { | |||
| Challenge = challenge; | |||
| InnerResult = innerResult; | |||
| } | |||
| public AuthenticationHeaderValue Challenge { get; } | |||
| public IHttpActionResult InnerResult { get; } | |||
| public async Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken) | |||
| { | |||
| HttpResponseMessage response = await InnerResult.ExecuteAsync(cancellationToken); | |||
| if (response.StatusCode == HttpStatusCode.Unauthorized) | |||
| { | |||
| // Only add one challenge per authentication scheme. | |||
| if (response.Headers.WwwAuthenticate.All(h => h.Scheme != Challenge.Scheme)) | |||
| { | |||
| response.Headers.WwwAuthenticate.Add(Challenge); | |||
| } | |||
| } | |||
| return response; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,34 @@ | |||
| using System.Net; | |||
| using System.Web.Http; | |||
| namespace BlackRock.Reporting.API.Jwt.Filters | |||
| { | |||
| public class AuthenticationFailureResult : IHttpActionResult | |||
| { | |||
| public AuthenticationFailureResult(string reasonPhrase, HttpRequestMessage request) | |||
| { | |||
| ReasonPhrase = reasonPhrase; | |||
| Request = request; | |||
| } | |||
| public string ReasonPhrase { get; } | |||
| public HttpRequestMessage Request { get; } | |||
| public Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken) | |||
| { | |||
| return Task.FromResult(Execute()); | |||
| } | |||
| private HttpResponseMessage Execute() | |||
| { | |||
| HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Unauthorized) | |||
| { | |||
| RequestMessage = Request, | |||
| ReasonPhrase = ReasonPhrase | |||
| }; | |||
| return response; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,28 @@ | |||
| using System.Net.Http.Headers; | |||
| using System.Web.Http.Filters; | |||
| namespace BlackRock.Reporting.API.Jwt.Filters | |||
| { | |||
| public static class HttpAuthenticationChallengeContextExtensions | |||
| { | |||
| public static void ChallengeWith(this HttpAuthenticationChallengeContext context, string scheme) | |||
| { | |||
| ChallengeWith(context, new AuthenticationHeaderValue(scheme)); | |||
| } | |||
| public static void ChallengeWith(this HttpAuthenticationChallengeContext context, string scheme, string parameter) | |||
| { | |||
| ChallengeWith(context, new AuthenticationHeaderValue(scheme, parameter)); | |||
| } | |||
| public static void ChallengeWith(this HttpAuthenticationChallengeContext context, AuthenticationHeaderValue challenge) | |||
| { | |||
| if (context == null) | |||
| { | |||
| throw new ArgumentNullException(nameof(context)); | |||
| } | |||
| context.Result = new AddChallengeOnUnauthorizedResult(challenge, context.Result); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,95 @@ | |||
| using System.Security.Claims; | |||
| using System.Security.Principal; | |||
| using System.Web.Http.Filters; | |||
| namespace BlackRock.Reporting.API.Jwt.Filters | |||
| { | |||
| public class Authentication : Attribute, IAuthenticationFilter | |||
| { | |||
| public string Realm { get; set; } | |||
| public bool AllowMultiple => false; | |||
| public async Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken) | |||
| { | |||
| var request = context.Request; | |||
| var authorization = request.Headers.Authorization; | |||
| if (authorization == null || authorization.Scheme != "Bearer") | |||
| return; | |||
| if (string.IsNullOrEmpty(authorization.Parameter)) | |||
| { | |||
| context.ErrorResult = new AuthenticationFailureResult("Missing Jwt Token", request); | |||
| return; | |||
| } | |||
| var token = authorization.Parameter; | |||
| var principal = await AuthenticateJwtToken(token); | |||
| if (principal == null) | |||
| context.ErrorResult = new AuthenticationFailureResult("Invalid token", request); | |||
| else | |||
| context.Principal = principal; | |||
| } | |||
| private static bool ValidateToken(string token, out string username) | |||
| { | |||
| username = null; | |||
| var simplePrinciple = new ClaimsPrincipal();// JwtManager.GetPrincipal(token); | |||
| var identity = simplePrinciple?.Identity as ClaimsIdentity; | |||
| if (identity == null) | |||
| return false; | |||
| if (!identity.IsAuthenticated) | |||
| return false; | |||
| var usernameClaim = identity.FindFirst(ClaimTypes.Name); | |||
| username = usernameClaim?.Value; | |||
| if (string.IsNullOrEmpty(username)) | |||
| return false; | |||
| // More validate to check whether username exists in system | |||
| return true; | |||
| } | |||
| protected Task<IPrincipal> AuthenticateJwtToken(string token) | |||
| { | |||
| if (ValidateToken(token, out var username)) | |||
| { | |||
| // based on username to get more information from database in order to build local identity | |||
| var claims = new List<Claim> | |||
| { | |||
| new Claim(ClaimTypes.Name, username) | |||
| // Add more claims if needed: Roles, ... | |||
| }; | |||
| var identity = new ClaimsIdentity(claims, "Jwt"); | |||
| IPrincipal user = new ClaimsPrincipal(identity); | |||
| return Task.FromResult(user); | |||
| } | |||
| return Task.FromResult<IPrincipal>(null); | |||
| } | |||
| public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken) | |||
| { | |||
| Challenge(context); | |||
| return Task.FromResult(0); | |||
| } | |||
| private void Challenge(HttpAuthenticationChallengeContext context) | |||
| { | |||
| string parameter = null; | |||
| if (!string.IsNullOrEmpty(Realm)) | |||
| parameter = "realm=\"" + Realm + "\""; | |||
| context.ChallengeWith("Bearer", parameter); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,17 @@ | |||
| using System.Security.Cryptography; | |||
| namespace BlackRock.Reporting.API.Jwt | |||
| { | |||
| public static class RefreshTokenGenerator | |||
| { | |||
| public static string GenerateToken() | |||
| { | |||
| var randomNumber = new byte[32]; | |||
| using (var radnomNumberGenerator = RandomNumberGenerator.Create()) | |||
| { | |||
| radnomNumberGenerator.GetBytes(randomNumber); | |||
| return Convert.ToBase64String(randomNumber); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1,19 +1,17 @@ | |||
| using AutoMapper; | |||
| using PuppeteerSharp; | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using BlackRock.Reporting.API.Mediator.Model; | |||
| using BlackRock.Reporting.API.Mediator.Dto; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Dto; | |||
| namespace BlackRock.Reporting.API.Profiles | |||
| namespace BlackRock.Reporting.API.Mapping.DTOToEntity | |||
| { | |||
| public class Profiler : Profile | |||
| public class PDFMapping : Profile | |||
| { | |||
| public Profiler() | |||
| public PDFMapping() | |||
| { | |||
| CreateMap<OptionsForPdf, PdfOptions>().ConvertUsing<OptionsForPdfConverter>(); | |||
| CreateMap<User, UserDto>().ReverseMap(); | |||
| CreateMap<User, UserCommand>().ReverseMap(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,16 @@ | |||
| using AutoMapper; | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Dto; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | |||
| namespace BlackRock.Reporting.API.Mapping | |||
| { | |||
| public class UserMappingDTOToEntity : Profile | |||
| { | |||
| public UserMappingDTOToEntity() | |||
| { | |||
| CreateMap<UserDto, User>(); | |||
| CreateMap<UserCommand, User>(); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,16 @@ | |||
| using AutoMapper; | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Dto; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | |||
| namespace BlackRock.Reporting.API.Mapping.DomainToDTO | |||
| { | |||
| public class UserMappingDomainToDTO : Profile | |||
| { | |||
| public UserMappingDomainToDTO() | |||
| { | |||
| CreateMap<User, UserDto>(); | |||
| CreateMap<User, UserCommand>(); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,65 @@ | |||
| using BlackRock.Reporting.API.Authentication; | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using BlackRock.Reporting.API.Mediator.AuthenticationMediator.Models; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | |||
| using MediatR; | |||
| using Microsoft.AspNetCore.Identity; | |||
| namespace BlackRock.Reporting.API.Mediator.AuthenticationMediator.Commands | |||
| { | |||
| public class LoginCommand : IRequest<Result<CredentialsCommand>> | |||
| { | |||
| public string Username { get; set; } | |||
| public string Password { get; set; } | |||
| } | |||
| public class LoginCommandHandlers : IRequestHandler<LoginCommand, Result<CredentialsCommand>> | |||
| { | |||
| private readonly ILogger<LoginCommand> logger; | |||
| private readonly JwtManager jwtManager; | |||
| private readonly RefreshTokenManager refreshTokenManager; | |||
| private readonly UserManager<ApplicationUser> userManager; | |||
| public LoginCommandHandlers(ILogger<LoginCommand> logger, JwtManager jwtManager, RefreshTokenManager refreshTokenManager, UserManager<ApplicationUser> userManager) | |||
| { | |||
| this.logger = logger; | |||
| this.jwtManager = jwtManager; | |||
| this.refreshTokenManager = refreshTokenManager; | |||
| this.userManager = userManager; | |||
| } | |||
| public async Task<Result<CredentialsCommand>> Handle(LoginCommand command, CancellationToken cancellationToken) | |||
| { | |||
| if (command is null) | |||
| throw new ArgumentException($"Parameter {nameof(command)} must not be null"); | |||
| try | |||
| { | |||
| var user = await userManager.FindByNameAsync(command.Username); | |||
| if (user != null && await userManager.CheckPasswordAsync(user, command.Password)) | |||
| { | |||
| var token = jwtManager.GenerateToken(command.Username); | |||
| await refreshTokenManager.RemoveRefreshToken(user); | |||
| var refreshToken = await refreshTokenManager.GenerateRefreshToken(user); | |||
| return new Result<CredentialsCommand> | |||
| { | |||
| Data = new CredentialsCommand | |||
| { | |||
| RefreshToken = refreshToken, | |||
| JwtToken = token | |||
| } | |||
| }; | |||
| } | |||
| return new Result<CredentialsCommand> | |||
| { | |||
| IsSuccess = false, | |||
| Error = "Invalid username and password" | |||
| }; | |||
| } | |||
| catch (Exception ex) | |||
| { | |||
| logger.LogError(ex, "Faild to add data to DB."); | |||
| return new Result<CredentialsCommand> { IsSuccess = false, Error = "Faild to add data to DB." }; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,60 @@ | |||
| using BlackRock.Reporting.API.Authentication; | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using BlackRock.Reporting.API.Mediator.AuthenticationMediator.Models; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | |||
| using MediatR; | |||
| using Microsoft.AspNetCore.Identity; | |||
| namespace BlackRock.Reporting.API.Mediator.AuthenticationMediator.Commands | |||
| { | |||
| public class LogoutCommand : CredentialsCommand, IRequest<Result<bool>> | |||
| { | |||
| } | |||
| public class LogoutCommandHandlers : IRequestHandler<LogoutCommand, Result<bool>> | |||
| { | |||
| private readonly ILogger<LogoutCommand> logger; | |||
| private readonly JwtManager jwtManager; | |||
| private readonly RefreshTokenManager refreshTokenManager; | |||
| private readonly UserManager<ApplicationUser> userManager; | |||
| public LogoutCommandHandlers(ILogger<LogoutCommand> logger, JwtManager jwtManager, RefreshTokenManager refreshTokenManager, UserManager<ApplicationUser> userManager) | |||
| { | |||
| this.logger = logger; | |||
| this.jwtManager = jwtManager; | |||
| this.refreshTokenManager = refreshTokenManager; | |||
| this.userManager = userManager; | |||
| } | |||
| public async Task<Result<bool>> Handle(LogoutCommand command, CancellationToken cancellationToken) | |||
| { | |||
| if (command is null) | |||
| throw new ArgumentException($"Parameter {nameof(command)} must not be null"); | |||
| try | |||
| { | |||
| // this checks is jwt token correct | |||
| var userName = jwtManager.GetUserName(command.JwtToken); | |||
| var user = await userManager.FindByNameAsync(userName); | |||
| if (!(await refreshTokenManager.ValidateRefreshToken(user, command.RefreshToken))) | |||
| return new Result<bool> | |||
| { | |||
| IsSuccess = false, | |||
| Error = "Invalid token" | |||
| }; | |||
| await refreshTokenManager.RemoveRefreshToken(user); | |||
| return new Result<bool> | |||
| { | |||
| Data = true | |||
| }; | |||
| } | |||
| catch (Exception ex) | |||
| { | |||
| logger.LogError(ex, "Faild to add data to DB."); | |||
| return new Result<bool> { IsSuccess = false, Error = "Faild to add data to DB." }; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,63 @@ | |||
| using BlackRock.Reporting.API.Authentication; | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using BlackRock.Reporting.API.Mediator.AuthenticationMediator.Models; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | |||
| using MediatR; | |||
| using Microsoft.AspNetCore.Identity; | |||
| namespace BlackRock.Reporting.API.Mediator.AuthenticationMediator.Commands | |||
| { | |||
| public class RefreshCommand : CredentialsCommand, IRequest<Result<CredentialsCommand>> | |||
| { | |||
| } | |||
| public class RefreshCommandHandlers : IRequestHandler<RefreshCommand, Result<CredentialsCommand>> | |||
| { | |||
| private readonly ILogger<RefreshCommand> logger; | |||
| private readonly JwtManager jwtManager; | |||
| private readonly RefreshTokenManager refreshTokenManager; | |||
| private readonly UserManager<ApplicationUser> userManager; | |||
| public RefreshCommandHandlers(ILogger<RefreshCommand> logger, JwtManager jwtManager, RefreshTokenManager refreshTokenManager, UserManager<ApplicationUser> userManager) | |||
| { | |||
| this.logger = logger; | |||
| this.jwtManager = jwtManager; | |||
| this.refreshTokenManager = refreshTokenManager; | |||
| this.userManager = userManager; | |||
| } | |||
| public async Task<Result<CredentialsCommand>> Handle(RefreshCommand command, CancellationToken cancellationToken) | |||
| { | |||
| if (command is null) | |||
| throw new ArgumentException($"Parameter {nameof(command)} must not be null"); | |||
| try | |||
| { | |||
| var userName = jwtManager.GetUserName(command.JwtToken); | |||
| var user = await userManager.FindByNameAsync(userName); | |||
| if (!(await refreshTokenManager.ValidateRefreshToken(user, command.RefreshToken))) | |||
| throw new UnauthorizedAccessException("Invalid token"); | |||
| var token = jwtManager.GenerateToken(userName); | |||
| if (token == null) | |||
| throw new UnauthorizedAccessException("Token is not valid"); | |||
| return new Result<CredentialsCommand> | |||
| { | |||
| Data = new CredentialsCommand | |||
| { | |||
| JwtToken = token, | |||
| RefreshToken = command.RefreshToken | |||
| } | |||
| }; | |||
| } | |||
| catch (Exception ex) | |||
| { | |||
| logger.LogError(ex, "Faild to add data to DB."); | |||
| return new Result<CredentialsCommand> { IsSuccess = false, Error = "Faild to add data to DB." }; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,8 @@ | |||
| namespace BlackRock.Reporting.API.Mediator.AuthenticationMediator.Models | |||
| { | |||
| public class CredentialsCommand | |||
| { | |||
| public string JwtToken { get; set; } | |||
| public string RefreshToken { get; set; } | |||
| } | |||
| } | |||
| @@ -0,0 +1,14 @@ | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | |||
| namespace BlackRock.Reporting.API.Mediator.DocumentMediator | |||
| { | |||
| public interface IDocumentMediator | |||
| { | |||
| Task<Result<Document>> GetDocument(int id); | |||
| Task<Result<PaggingCollection<Document>>> GetDocuments(PaggingAndFiltering query); | |||
| Task<Result<int>> CreateDocument(CreateDocumentForm form); | |||
| Task<Result<int>> UpdateDocument(UpdateDocumentForm form); | |||
| Task<Result<int>> DeleteDocument(int id); | |||
| } | |||
| } | |||
| @@ -0,0 +1,6 @@ | |||
| namespace BlackRock.Reporting.API.Mediator.DocumentMediator | |||
| { | |||
| public class Document | |||
| { | |||
| } | |||
| } | |||
| @@ -0,0 +1,6 @@ | |||
| namespace BlackRock.Reporting.API.Mediator.DocumentMediator | |||
| { | |||
| public class CreateDocumentForm | |||
| { | |||
| } | |||
| } | |||
| @@ -0,0 +1,6 @@ | |||
| namespace BlackRock.Reporting.API.Mediator.DocumentMediator | |||
| { | |||
| public class UpdateDocumentForm | |||
| { | |||
| } | |||
| } | |||
| @@ -1,17 +0,0 @@ | |||
| using System.ComponentModel.DataAnnotations; | |||
| namespace BlackRock.Reporting.API.Mediator.Model | |||
| { | |||
| public class UserCommand | |||
| { | |||
| [Required] | |||
| public string Name { get; } | |||
| [Required] | |||
| public string Email { get; } | |||
| public UserCommand(string Name,string Email) | |||
| { | |||
| this.Name = Name; | |||
| this.Email = Email; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,14 +0,0 @@ | |||
| using System.ComponentModel.DataAnnotations; | |||
| namespace BlackRock.Reporting.API.Mediator.Model | |||
| { | |||
| public class UserQuery | |||
| { | |||
| [Required] | |||
| public int Id { get; } | |||
| public UserQuery(int id) | |||
| { | |||
| Id = id; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,31 +1,28 @@ | |||
| using AutoMapper; | |||
| using BlackRock.Reporting.API.Core; | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using BlackRock.Reporting.API.Mediator.Model; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | |||
| using MediatR; | |||
| namespace BlackRock.Reporting.API.Mediator.Commands | |||
| namespace BlackRock.Reporting.API.Mediator.UserMediator.Commands | |||
| { | |||
| public class CreateUsersCommand : UserCommand, IRequest<Result<int>> | |||
| public class CreateUserCommand : UserCommand, IRequest<Result<int>> | |||
| { | |||
| public CreateUsersCommand(string Name, string Email) : base(Name, Email) | |||
| { | |||
| } | |||
| } | |||
| public class CreateUsersCommandHandlers : IRequestHandler<CreateUsersCommand, Result<int>> | |||
| public class CreateUserCommandHandlers : IRequestHandler<CreateUserCommand, Result<int>> | |||
| { | |||
| private readonly ILogger<CreateUsersCommandHandlers> logger; | |||
| private readonly ILogger<CreateUserCommandHandlers> logger; | |||
| private readonly IMapper mapper; | |||
| private readonly IUnitOfWork unitOfWork; | |||
| public CreateUsersCommandHandlers(ILogger<CreateUsersCommandHandlers> logger, IMapper mapper, IUnitOfWork unitOfWork) | |||
| public CreateUserCommandHandlers(ILogger<CreateUserCommandHandlers> logger, IMapper mapper, IUnitOfWork unitOfWork) | |||
| { | |||
| this.unitOfWork = unitOfWork; | |||
| this.mapper = mapper; | |||
| this.logger = logger; | |||
| } | |||
| public async Task<Result<int>> Handle(CreateUsersCommand command, CancellationToken cancellationToken) | |||
| public async Task<Result<int>> Handle(CreateUserCommand command, CancellationToken cancellationToken) | |||
| { | |||
| if (command is null) | |||
| throw new ArgumentException($"Parameter {nameof(command)} must not be null"); | |||
| @@ -37,11 +34,11 @@ namespace BlackRock.Reporting.API.Mediator.Commands | |||
| await unitOfWork.UsersRepository.AddAsync(user); | |||
| await unitOfWork.SaveChangesAsync(); | |||
| logger.LogInformation($"User with id {user.Id} has been created successfully"); | |||
| return new Result<int> { Data = user.Id}; | |||
| return new Result<int> { Data = user.Id }; | |||
| } | |||
| catch (Exception ex) | |||
| { | |||
| logger.LogError(ex,"Faild to add data to DB."); | |||
| logger.LogError(ex, "Faild to add data to DB."); | |||
| return new Result<int> { IsSuccess = false, Error = "Faild to add data to DB." }; | |||
| } | |||
| } | |||
| @@ -1,15 +1,13 @@ | |||
| using AutoMapper; | |||
| using BlackRock.Reporting.API.Core; | |||
| using BlackRock.Reporting.API.Mediator.Model; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | |||
| using MediatR; | |||
| namespace BlackRock.Reporting.API.Mediator.Commands | |||
| namespace BlackRock.Reporting.API.Mediator.UserMediator.Commands | |||
| { | |||
| public class DeleteUsersCommand : UserQuery, IRequest<Result<int>> | |||
| public class DeleteUsersCommand : IRequest<Result<int>> | |||
| { | |||
| public DeleteUsersCommand(int id) : base(id) | |||
| { | |||
| } | |||
| public int Id { get; set; } | |||
| } | |||
| public class DeleteUsersCommandHandlers : IRequestHandler<DeleteUsersCommand, Result<int>> | |||
| @@ -1,35 +1,31 @@ | |||
| using AutoMapper; | |||
| using BlackRock.Reporting.API.Core; | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using BlackRock.Reporting.API.Mediator.Dto; | |||
| using BlackRock.Reporting.API.Mediator.Model; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Dto; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | |||
| using MediatR; | |||
| namespace BlackRock.Reporting.API.Mediator.Commands | |||
| namespace BlackRock.Reporting.API.Mediator.UserMediator.Commands | |||
| { | |||
| public class UpdateAllUsersCommand : IRequest<Result<UserDto>> | |||
| public class UpdateUserCommand : IRequest<Result<UserDto>> | |||
| { | |||
| public UserCommand User { get; } | |||
| public int Id { get; } | |||
| public UpdateAllUsersCommand(int id, UserCommand user) | |||
| { | |||
| this.Id = id; | |||
| this.User = user; | |||
| } | |||
| public UserCommand User { get;set; } | |||
| public int Id { get;set; } | |||
| } | |||
| public class UpdateAllUsersCommandHandlers : IRequestHandler<UpdateAllUsersCommand, Result<UserDto>> | |||
| public class UpdateUserCommandHandlers : IRequestHandler<UpdateUserCommand, Result<UserDto>> | |||
| { | |||
| private readonly ILogger<UpdateAllUsersCommandHandlers> logger; | |||
| private readonly ILogger<UpdateUserCommandHandlers> logger; | |||
| private readonly IMapper mapper; | |||
| private readonly IUnitOfWork unitOfWork; | |||
| public UpdateAllUsersCommandHandlers(ILogger<UpdateAllUsersCommandHandlers> logger, IMapper mapper, IUnitOfWork unitOfWork) | |||
| public UpdateUserCommandHandlers(ILogger<UpdateUserCommandHandlers> logger, IMapper mapper, IUnitOfWork unitOfWork) | |||
| { | |||
| this.unitOfWork = unitOfWork; | |||
| this.mapper = mapper; | |||
| this.logger = logger; | |||
| } | |||
| public async Task<Result<UserDto>> Handle(UpdateAllUsersCommand command, CancellationToken cancellationToken) | |||
| public async Task<Result<UserDto>> Handle(UpdateUserCommand command, CancellationToken cancellationToken) | |||
| { | |||
| if (command.Id <= 0) | |||
| throw new ArgumentException($"Parameter {nameof(command.Id)} must not be grater than 0"); | |||
| @@ -1,35 +1,31 @@ | |||
| using AutoMapper; | |||
| using BlackRock.Reporting.API.Mediator.Dto; | |||
| using BlackRock.Reporting.API.Mediator.Model; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Dto; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | |||
| using BlackRock.Reporting.API.Core; | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using MediatR; | |||
| namespace BlackRock.Reporting.API.Mediator.Commands | |||
| namespace BlackRock.Reporting.API.Mediator.UserMediator.Commands | |||
| { | |||
| public class UpdateEmailUsersCommand : IRequest<Result<UserDto>> | |||
| public class UpdateUserEmailCommand : IRequest<Result<UserDto>> | |||
| { | |||
| public UserCommand User { get; } | |||
| public int Id { get; } | |||
| public UpdateEmailUsersCommand(int id, UserCommand user) | |||
| { | |||
| this.Id = id; | |||
| this.User = user; | |||
| } | |||
| public UserCommand User {set;get;} | |||
| public int Id { get; set;} | |||
| } | |||
| public class UpdateEmailUsersCommandHandlers : IRequestHandler<UpdateEmailUsersCommand, Result<UserDto>> | |||
| public class UpdateUserEmailCommandHandlers : IRequestHandler<UpdateUserEmailCommand, Result<UserDto>> | |||
| { | |||
| private readonly ILogger<UpdateEmailUsersCommandHandlers> logger; | |||
| private readonly ILogger<UpdateUserEmailCommandHandlers> logger; | |||
| private readonly IMapper mapper; | |||
| private readonly IUnitOfWork unitOfWork; | |||
| public UpdateEmailUsersCommandHandlers(ILogger<UpdateEmailUsersCommandHandlers> logger, IMapper mapper, IUnitOfWork unitOfWork) | |||
| public UpdateUserEmailCommandHandlers(ILogger<UpdateUserEmailCommandHandlers> logger, IMapper mapper, IUnitOfWork unitOfWork) | |||
| { | |||
| this.unitOfWork = unitOfWork; | |||
| this.mapper = mapper; | |||
| this.logger = logger; | |||
| } | |||
| public async Task<Result<UserDto>> Handle(UpdateEmailUsersCommand command, CancellationToken cancellationToken) | |||
| public async Task<Result<UserDto>> Handle(UpdateUserEmailCommand command, CancellationToken cancellationToken) | |||
| { | |||
| if (command.Id <= 0) | |||
| throw new ArgumentException($"Parameter {nameof(command.Id)} must not be grater than 0"); | |||
| @@ -1,4 +1,4 @@ | |||
| namespace BlackRock.Reporting.API.Mediator.Dto | |||
| namespace BlackRock.Reporting.API.Mediator.UserMediator.Dto | |||
| { | |||
| public class UserDto | |||
| { | |||
| @@ -1,4 +1,4 @@ | |||
| namespace BlackRock.Reporting.API.Mediator.Model | |||
| namespace BlackRock.Reporting.API.Mediator.UserMediator.Model | |||
| { | |||
| public class Result<TData> | |||
| { | |||
| @@ -0,0 +1,13 @@ | |||
| using System.ComponentModel.DataAnnotations; | |||
| namespace BlackRock.Reporting.API.Mediator.UserMediator.Model | |||
| { | |||
| public class UserCommand | |||
| { | |||
| [Required] | |||
| public string Name { get;set; } | |||
| [Required] | |||
| public string Email { get;set; } | |||
| } | |||
| } | |||
| @@ -1,11 +1,11 @@ | |||
| using AutoMapper; | |||
| using BlackRock.Reporting.API.Core; | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using BlackRock.Reporting.API.Mediator.Model; | |||
| using BlackRock.Reporting.API.Mediator.Dto; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Dto; | |||
| using MediatR; | |||
| namespace BlackRock.Reporting.API.Mediator.Queries | |||
| namespace BlackRock.Reporting.API.Mediator.UserMediator.Queries | |||
| { | |||
| public class GetAllUsersQuery : UserPaggingAndFiltering, IRequest<Result<PaggingCollection<UserDto>>> | |||
| { | |||
| @@ -1,33 +1,31 @@ | |||
| using AutoMapper; | |||
| using BlackRock.Reporting.API.Mediator.Dto; | |||
| using BlackRock.Reporting.API.Mediator.Model; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Dto; | |||
| using BlackRock.Reporting.API.Mediator.UserMediator.Model; | |||
| using BlackRock.Reporting.API.Core; | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using MediatR; | |||
| namespace BlackRock.Reporting.API.Mediator.Queries | |||
| namespace BlackRock.Reporting.API.Mediator.UserMediator.Queries | |||
| { | |||
| public class GetUsersQuery : UserQuery, IRequest<Result<UserDto>> | |||
| public class GetUserQuery : IRequest<Result<UserDto>> | |||
| { | |||
| public GetUsersQuery(int id) : base(id) | |||
| { | |||
| } | |||
| public int Id { get; set; } | |||
| } | |||
| public class GetUsersQueryHandlers : IRequestHandler<GetUsersQuery, Result<UserDto>> | |||
| public class GetUserQueryHandlers : IRequestHandler<GetUserQuery, Result<UserDto>> | |||
| { | |||
| private readonly ILogger<GetUsersQueryHandlers> logger; | |||
| private readonly ILogger<GetUserQueryHandlers> logger; | |||
| private readonly IMapper mapper; | |||
| private readonly IUsersRepository repository; | |||
| private readonly IUnitOfWork unitOfWork; | |||
| public GetUsersQueryHandlers(ILogger<GetUsersQueryHandlers> logger, IMapper mapper, IUsersRepository repository, IUnitOfWork unitOfWork) | |||
| public GetUserQueryHandlers(ILogger<GetUserQueryHandlers> logger, IMapper mapper, IUsersRepository repository, IUnitOfWork unitOfWork) | |||
| { | |||
| this.unitOfWork = unitOfWork; | |||
| this.repository = repository; | |||
| this.mapper = mapper; | |||
| this.logger = logger; | |||
| } | |||
| public async Task<Result<UserDto>> Handle(GetUsersQuery command, CancellationToken cancellationToken) | |||
| public async Task<Result<UserDto>> Handle(GetUserQuery command, CancellationToken cancellationToken) | |||
| { | |||
| if (command.Id <= 0) | |||
| throw new ArgumentException($"Parameter {nameof(command.Id)} must not be grater than 0"); | |||
| @@ -0,0 +1,284 @@ | |||
| // <auto-generated /> | |||
| using System; | |||
| using BlackRock.Reporting.API.Persistence; | |||
| using Microsoft.EntityFrameworkCore; | |||
| using Microsoft.EntityFrameworkCore.Infrastructure; | |||
| using Microsoft.EntityFrameworkCore.Migrations; | |||
| using Microsoft.EntityFrameworkCore.Storage.ValueConversion; | |||
| #nullable disable | |||
| namespace BlackRock.Reporting.API.Migrations | |||
| { | |||
| [DbContext(typeof(BRDbContext))] | |||
| [Migration("20211129132834_AddedAuth")] | |||
| partial class AddedAuth | |||
| { | |||
| protected override void BuildTargetModel(ModelBuilder modelBuilder) | |||
| { | |||
| #pragma warning disable 612, 618 | |||
| modelBuilder.HasAnnotation("ProductVersion", "6.0.0"); | |||
| modelBuilder.Entity("BlackRock.Reporting.API.Core.Models.ApplicationUser", b => | |||
| { | |||
| b.Property<string>("Id") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<int>("AccessFailedCount") | |||
| .HasColumnType("INTEGER"); | |||
| b.Property<string>("ConcurrencyStamp") | |||
| .IsConcurrencyToken() | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("Email") | |||
| .HasMaxLength(256) | |||
| .HasColumnType("TEXT"); | |||
| b.Property<bool>("EmailConfirmed") | |||
| .HasColumnType("INTEGER"); | |||
| b.Property<bool>("LockoutEnabled") | |||
| .HasColumnType("INTEGER"); | |||
| b.Property<DateTimeOffset?>("LockoutEnd") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("NormalizedEmail") | |||
| .HasMaxLength(256) | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("NormalizedUserName") | |||
| .HasMaxLength(256) | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("PasswordHash") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("PhoneNumber") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<bool>("PhoneNumberConfirmed") | |||
| .HasColumnType("INTEGER"); | |||
| b.Property<string>("SecurityStamp") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<bool>("TwoFactorEnabled") | |||
| .HasColumnType("INTEGER"); | |||
| b.Property<string>("UserName") | |||
| .HasMaxLength(256) | |||
| .HasColumnType("TEXT"); | |||
| b.HasKey("Id"); | |||
| b.HasIndex("NormalizedEmail") | |||
| .HasDatabaseName("EmailIndex"); | |||
| b.HasIndex("NormalizedUserName") | |||
| .IsUnique() | |||
| .HasDatabaseName("UserNameIndex"); | |||
| b.ToTable("AspNetUsers", (string)null); | |||
| }); | |||
| modelBuilder.Entity("BlackRock.Reporting.API.Core.Models.User", b => | |||
| { | |||
| b.Property<int>("Id") | |||
| .ValueGeneratedOnAdd() | |||
| .HasColumnType("INTEGER"); | |||
| b.Property<string>("Email") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("Name") | |||
| .HasColumnType("TEXT"); | |||
| b.HasKey("Id"); | |||
| b.ToTable("Users"); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => | |||
| { | |||
| b.Property<string>("Id") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("ConcurrencyStamp") | |||
| .IsConcurrencyToken() | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("Name") | |||
| .HasMaxLength(256) | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("NormalizedName") | |||
| .HasMaxLength(256) | |||
| .HasColumnType("TEXT"); | |||
| b.HasKey("Id"); | |||
| b.HasIndex("NormalizedName") | |||
| .IsUnique() | |||
| .HasDatabaseName("RoleNameIndex"); | |||
| b.ToTable("AspNetRoles", (string)null); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b => | |||
| { | |||
| b.Property<int>("Id") | |||
| .ValueGeneratedOnAdd() | |||
| .HasColumnType("INTEGER"); | |||
| b.Property<string>("ClaimType") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("ClaimValue") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("RoleId") | |||
| .IsRequired() | |||
| .HasColumnType("TEXT"); | |||
| b.HasKey("Id"); | |||
| b.HasIndex("RoleId"); | |||
| b.ToTable("AspNetRoleClaims", (string)null); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b => | |||
| { | |||
| b.Property<int>("Id") | |||
| .ValueGeneratedOnAdd() | |||
| .HasColumnType("INTEGER"); | |||
| b.Property<string>("ClaimType") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("ClaimValue") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("UserId") | |||
| .IsRequired() | |||
| .HasColumnType("TEXT"); | |||
| b.HasKey("Id"); | |||
| b.HasIndex("UserId"); | |||
| b.ToTable("AspNetUserClaims", (string)null); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b => | |||
| { | |||
| b.Property<string>("LoginProvider") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("ProviderKey") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("ProviderDisplayName") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("UserId") | |||
| .IsRequired() | |||
| .HasColumnType("TEXT"); | |||
| b.HasKey("LoginProvider", "ProviderKey"); | |||
| b.HasIndex("UserId"); | |||
| b.ToTable("AspNetUserLogins", (string)null); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b => | |||
| { | |||
| b.Property<string>("UserId") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("RoleId") | |||
| .HasColumnType("TEXT"); | |||
| b.HasKey("UserId", "RoleId"); | |||
| b.HasIndex("RoleId"); | |||
| b.ToTable("AspNetUserRoles", (string)null); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b => | |||
| { | |||
| b.Property<string>("UserId") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("LoginProvider") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("Name") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("Value") | |||
| .HasColumnType("TEXT"); | |||
| b.HasKey("UserId", "LoginProvider", "Name"); | |||
| b.ToTable("AspNetUserTokens", (string)null); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b => | |||
| { | |||
| b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) | |||
| .WithMany() | |||
| .HasForeignKey("RoleId") | |||
| .OnDelete(DeleteBehavior.Cascade) | |||
| .IsRequired(); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b => | |||
| { | |||
| b.HasOne("BlackRock.Reporting.API.Core.Models.ApplicationUser", null) | |||
| .WithMany() | |||
| .HasForeignKey("UserId") | |||
| .OnDelete(DeleteBehavior.Cascade) | |||
| .IsRequired(); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b => | |||
| { | |||
| b.HasOne("BlackRock.Reporting.API.Core.Models.ApplicationUser", null) | |||
| .WithMany() | |||
| .HasForeignKey("UserId") | |||
| .OnDelete(DeleteBehavior.Cascade) | |||
| .IsRequired(); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b => | |||
| { | |||
| b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) | |||
| .WithMany() | |||
| .HasForeignKey("RoleId") | |||
| .OnDelete(DeleteBehavior.Cascade) | |||
| .IsRequired(); | |||
| b.HasOne("BlackRock.Reporting.API.Core.Models.ApplicationUser", null) | |||
| .WithMany() | |||
| .HasForeignKey("UserId") | |||
| .OnDelete(DeleteBehavior.Cascade) | |||
| .IsRequired(); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b => | |||
| { | |||
| b.HasOne("BlackRock.Reporting.API.Core.Models.ApplicationUser", null) | |||
| .WithMany() | |||
| .HasForeignKey("UserId") | |||
| .OnDelete(DeleteBehavior.Cascade) | |||
| .IsRequired(); | |||
| }); | |||
| #pragma warning restore 612, 618 | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,219 @@ | |||
| using System; | |||
| using Microsoft.EntityFrameworkCore.Migrations; | |||
| #nullable disable | |||
| namespace BlackRock.Reporting.API.Migrations | |||
| { | |||
| public partial class AddedAuth : Migration | |||
| { | |||
| protected override void Up(MigrationBuilder migrationBuilder) | |||
| { | |||
| migrationBuilder.CreateTable( | |||
| name: "AspNetRoles", | |||
| columns: table => new | |||
| { | |||
| Id = table.Column<string>(type: "TEXT", nullable: false), | |||
| Name = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true), | |||
| NormalizedName = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true), | |||
| ConcurrencyStamp = table.Column<string>(type: "TEXT", nullable: true) | |||
| }, | |||
| constraints: table => | |||
| { | |||
| table.PrimaryKey("PK_AspNetRoles", x => x.Id); | |||
| }); | |||
| migrationBuilder.CreateTable( | |||
| name: "AspNetUsers", | |||
| columns: table => new | |||
| { | |||
| Id = table.Column<string>(type: "TEXT", nullable: false), | |||
| UserName = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true), | |||
| NormalizedUserName = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true), | |||
| Email = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true), | |||
| NormalizedEmail = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true), | |||
| EmailConfirmed = table.Column<bool>(type: "INTEGER", nullable: false), | |||
| PasswordHash = table.Column<string>(type: "TEXT", nullable: true), | |||
| SecurityStamp = table.Column<string>(type: "TEXT", nullable: true), | |||
| ConcurrencyStamp = table.Column<string>(type: "TEXT", nullable: true), | |||
| PhoneNumber = table.Column<string>(type: "TEXT", nullable: true), | |||
| PhoneNumberConfirmed = table.Column<bool>(type: "INTEGER", nullable: false), | |||
| TwoFactorEnabled = table.Column<bool>(type: "INTEGER", nullable: false), | |||
| LockoutEnd = table.Column<DateTimeOffset>(type: "TEXT", nullable: true), | |||
| LockoutEnabled = table.Column<bool>(type: "INTEGER", nullable: false), | |||
| AccessFailedCount = table.Column<int>(type: "INTEGER", nullable: false) | |||
| }, | |||
| constraints: table => | |||
| { | |||
| table.PrimaryKey("PK_AspNetUsers", x => x.Id); | |||
| }); | |||
| migrationBuilder.CreateTable( | |||
| name: "AspNetRoleClaims", | |||
| columns: table => new | |||
| { | |||
| Id = table.Column<int>(type: "INTEGER", nullable: false) | |||
| .Annotation("Sqlite:Autoincrement", true), | |||
| RoleId = table.Column<string>(type: "TEXT", nullable: false), | |||
| ClaimType = table.Column<string>(type: "TEXT", nullable: true), | |||
| ClaimValue = table.Column<string>(type: "TEXT", nullable: true) | |||
| }, | |||
| constraints: table => | |||
| { | |||
| table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); | |||
| table.ForeignKey( | |||
| name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", | |||
| column: x => x.RoleId, | |||
| principalTable: "AspNetRoles", | |||
| principalColumn: "Id", | |||
| onDelete: ReferentialAction.Cascade); | |||
| }); | |||
| migrationBuilder.CreateTable( | |||
| name: "AspNetUserClaims", | |||
| columns: table => new | |||
| { | |||
| Id = table.Column<int>(type: "INTEGER", nullable: false) | |||
| .Annotation("Sqlite:Autoincrement", true), | |||
| UserId = table.Column<string>(type: "TEXT", nullable: false), | |||
| ClaimType = table.Column<string>(type: "TEXT", nullable: true), | |||
| ClaimValue = table.Column<string>(type: "TEXT", nullable: true) | |||
| }, | |||
| constraints: table => | |||
| { | |||
| table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); | |||
| table.ForeignKey( | |||
| name: "FK_AspNetUserClaims_AspNetUsers_UserId", | |||
| column: x => x.UserId, | |||
| principalTable: "AspNetUsers", | |||
| principalColumn: "Id", | |||
| onDelete: ReferentialAction.Cascade); | |||
| }); | |||
| migrationBuilder.CreateTable( | |||
| name: "AspNetUserLogins", | |||
| columns: table => new | |||
| { | |||
| LoginProvider = table.Column<string>(type: "TEXT", nullable: false), | |||
| ProviderKey = table.Column<string>(type: "TEXT", nullable: false), | |||
| ProviderDisplayName = table.Column<string>(type: "TEXT", nullable: true), | |||
| UserId = table.Column<string>(type: "TEXT", nullable: false) | |||
| }, | |||
| constraints: table => | |||
| { | |||
| table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); | |||
| table.ForeignKey( | |||
| name: "FK_AspNetUserLogins_AspNetUsers_UserId", | |||
| column: x => x.UserId, | |||
| principalTable: "AspNetUsers", | |||
| principalColumn: "Id", | |||
| onDelete: ReferentialAction.Cascade); | |||
| }); | |||
| migrationBuilder.CreateTable( | |||
| name: "AspNetUserRoles", | |||
| columns: table => new | |||
| { | |||
| UserId = table.Column<string>(type: "TEXT", nullable: false), | |||
| RoleId = table.Column<string>(type: "TEXT", nullable: false) | |||
| }, | |||
| constraints: table => | |||
| { | |||
| table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); | |||
| table.ForeignKey( | |||
| name: "FK_AspNetUserRoles_AspNetRoles_RoleId", | |||
| column: x => x.RoleId, | |||
| principalTable: "AspNetRoles", | |||
| principalColumn: "Id", | |||
| onDelete: ReferentialAction.Cascade); | |||
| table.ForeignKey( | |||
| name: "FK_AspNetUserRoles_AspNetUsers_UserId", | |||
| column: x => x.UserId, | |||
| principalTable: "AspNetUsers", | |||
| principalColumn: "Id", | |||
| onDelete: ReferentialAction.Cascade); | |||
| }); | |||
| migrationBuilder.CreateTable( | |||
| name: "AspNetUserTokens", | |||
| columns: table => new | |||
| { | |||
| UserId = table.Column<string>(type: "TEXT", nullable: false), | |||
| LoginProvider = table.Column<string>(type: "TEXT", nullable: false), | |||
| Name = table.Column<string>(type: "TEXT", nullable: false), | |||
| Value = table.Column<string>(type: "TEXT", nullable: true) | |||
| }, | |||
| constraints: table => | |||
| { | |||
| table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); | |||
| table.ForeignKey( | |||
| name: "FK_AspNetUserTokens_AspNetUsers_UserId", | |||
| column: x => x.UserId, | |||
| principalTable: "AspNetUsers", | |||
| principalColumn: "Id", | |||
| onDelete: ReferentialAction.Cascade); | |||
| }); | |||
| migrationBuilder.CreateIndex( | |||
| name: "IX_AspNetRoleClaims_RoleId", | |||
| table: "AspNetRoleClaims", | |||
| column: "RoleId"); | |||
| migrationBuilder.CreateIndex( | |||
| name: "RoleNameIndex", | |||
| table: "AspNetRoles", | |||
| column: "NormalizedName", | |||
| unique: true); | |||
| migrationBuilder.CreateIndex( | |||
| name: "IX_AspNetUserClaims_UserId", | |||
| table: "AspNetUserClaims", | |||
| column: "UserId"); | |||
| migrationBuilder.CreateIndex( | |||
| name: "IX_AspNetUserLogins_UserId", | |||
| table: "AspNetUserLogins", | |||
| column: "UserId"); | |||
| migrationBuilder.CreateIndex( | |||
| name: "IX_AspNetUserRoles_RoleId", | |||
| table: "AspNetUserRoles", | |||
| column: "RoleId"); | |||
| migrationBuilder.CreateIndex( | |||
| name: "EmailIndex", | |||
| table: "AspNetUsers", | |||
| column: "NormalizedEmail"); | |||
| migrationBuilder.CreateIndex( | |||
| name: "UserNameIndex", | |||
| table: "AspNetUsers", | |||
| column: "NormalizedUserName", | |||
| unique: true); | |||
| } | |||
| protected override void Down(MigrationBuilder migrationBuilder) | |||
| { | |||
| migrationBuilder.DropTable( | |||
| name: "AspNetRoleClaims"); | |||
| migrationBuilder.DropTable( | |||
| name: "AspNetUserClaims"); | |||
| migrationBuilder.DropTable( | |||
| name: "AspNetUserLogins"); | |||
| migrationBuilder.DropTable( | |||
| name: "AspNetUserRoles"); | |||
| migrationBuilder.DropTable( | |||
| name: "AspNetUserTokens"); | |||
| migrationBuilder.DropTable( | |||
| name: "AspNetRoles"); | |||
| migrationBuilder.DropTable( | |||
| name: "AspNetUsers"); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,4 +1,5 @@ | |||
| // <auto-generated /> | |||
| using System; | |||
| using BlackRock.Reporting.API.Persistence; | |||
| using Microsoft.EntityFrameworkCore; | |||
| using Microsoft.EntityFrameworkCore.Infrastructure; | |||
| @@ -16,7 +17,71 @@ namespace BlackRock.Reporting.API.Migrations | |||
| #pragma warning disable 612, 618 | |||
| modelBuilder.HasAnnotation("ProductVersion", "6.0.0"); | |||
| modelBuilder.Entity("BlackRock.Reporting.API.Models.User", b => | |||
| modelBuilder.Entity("BlackRock.Reporting.API.Core.Models.ApplicationUser", b => | |||
| { | |||
| b.Property<string>("Id") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<int>("AccessFailedCount") | |||
| .HasColumnType("INTEGER"); | |||
| b.Property<string>("ConcurrencyStamp") | |||
| .IsConcurrencyToken() | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("Email") | |||
| .HasMaxLength(256) | |||
| .HasColumnType("TEXT"); | |||
| b.Property<bool>("EmailConfirmed") | |||
| .HasColumnType("INTEGER"); | |||
| b.Property<bool>("LockoutEnabled") | |||
| .HasColumnType("INTEGER"); | |||
| b.Property<DateTimeOffset?>("LockoutEnd") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("NormalizedEmail") | |||
| .HasMaxLength(256) | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("NormalizedUserName") | |||
| .HasMaxLength(256) | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("PasswordHash") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("PhoneNumber") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<bool>("PhoneNumberConfirmed") | |||
| .HasColumnType("INTEGER"); | |||
| b.Property<string>("SecurityStamp") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<bool>("TwoFactorEnabled") | |||
| .HasColumnType("INTEGER"); | |||
| b.Property<string>("UserName") | |||
| .HasMaxLength(256) | |||
| .HasColumnType("TEXT"); | |||
| b.HasKey("Id"); | |||
| b.HasIndex("NormalizedEmail") | |||
| .HasDatabaseName("EmailIndex"); | |||
| b.HasIndex("NormalizedUserName") | |||
| .IsUnique() | |||
| .HasDatabaseName("UserNameIndex"); | |||
| b.ToTable("AspNetUsers", (string)null); | |||
| }); | |||
| modelBuilder.Entity("BlackRock.Reporting.API.Core.Models.User", b => | |||
| { | |||
| b.Property<int>("Id") | |||
| .ValueGeneratedOnAdd() | |||
| @@ -30,7 +95,186 @@ namespace BlackRock.Reporting.API.Migrations | |||
| b.HasKey("Id"); | |||
| b.ToTable("Users"); | |||
| b.ToTable("Users", (string)null); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => | |||
| { | |||
| b.Property<string>("Id") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("ConcurrencyStamp") | |||
| .IsConcurrencyToken() | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("Name") | |||
| .HasMaxLength(256) | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("NormalizedName") | |||
| .HasMaxLength(256) | |||
| .HasColumnType("TEXT"); | |||
| b.HasKey("Id"); | |||
| b.HasIndex("NormalizedName") | |||
| .IsUnique() | |||
| .HasDatabaseName("RoleNameIndex"); | |||
| b.ToTable("AspNetRoles", (string)null); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b => | |||
| { | |||
| b.Property<int>("Id") | |||
| .ValueGeneratedOnAdd() | |||
| .HasColumnType("INTEGER"); | |||
| b.Property<string>("ClaimType") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("ClaimValue") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("RoleId") | |||
| .IsRequired() | |||
| .HasColumnType("TEXT"); | |||
| b.HasKey("Id"); | |||
| b.HasIndex("RoleId"); | |||
| b.ToTable("AspNetRoleClaims", (string)null); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b => | |||
| { | |||
| b.Property<int>("Id") | |||
| .ValueGeneratedOnAdd() | |||
| .HasColumnType("INTEGER"); | |||
| b.Property<string>("ClaimType") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("ClaimValue") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("UserId") | |||
| .IsRequired() | |||
| .HasColumnType("TEXT"); | |||
| b.HasKey("Id"); | |||
| b.HasIndex("UserId"); | |||
| b.ToTable("AspNetUserClaims", (string)null); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b => | |||
| { | |||
| b.Property<string>("LoginProvider") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("ProviderKey") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("ProviderDisplayName") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("UserId") | |||
| .IsRequired() | |||
| .HasColumnType("TEXT"); | |||
| b.HasKey("LoginProvider", "ProviderKey"); | |||
| b.HasIndex("UserId"); | |||
| b.ToTable("AspNetUserLogins", (string)null); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b => | |||
| { | |||
| b.Property<string>("UserId") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("RoleId") | |||
| .HasColumnType("TEXT"); | |||
| b.HasKey("UserId", "RoleId"); | |||
| b.HasIndex("RoleId"); | |||
| b.ToTable("AspNetUserRoles", (string)null); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b => | |||
| { | |||
| b.Property<string>("UserId") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("LoginProvider") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("Name") | |||
| .HasColumnType("TEXT"); | |||
| b.Property<string>("Value") | |||
| .HasColumnType("TEXT"); | |||
| b.HasKey("UserId", "LoginProvider", "Name"); | |||
| b.ToTable("AspNetUserTokens", (string)null); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b => | |||
| { | |||
| b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) | |||
| .WithMany() | |||
| .HasForeignKey("RoleId") | |||
| .OnDelete(DeleteBehavior.Cascade) | |||
| .IsRequired(); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b => | |||
| { | |||
| b.HasOne("BlackRock.Reporting.API.Core.Models.ApplicationUser", null) | |||
| .WithMany() | |||
| .HasForeignKey("UserId") | |||
| .OnDelete(DeleteBehavior.Cascade) | |||
| .IsRequired(); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b => | |||
| { | |||
| b.HasOne("BlackRock.Reporting.API.Core.Models.ApplicationUser", null) | |||
| .WithMany() | |||
| .HasForeignKey("UserId") | |||
| .OnDelete(DeleteBehavior.Cascade) | |||
| .IsRequired(); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b => | |||
| { | |||
| b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) | |||
| .WithMany() | |||
| .HasForeignKey("RoleId") | |||
| .OnDelete(DeleteBehavior.Cascade) | |||
| .IsRequired(); | |||
| b.HasOne("BlackRock.Reporting.API.Core.Models.ApplicationUser", null) | |||
| .WithMany() | |||
| .HasForeignKey("UserId") | |||
| .OnDelete(DeleteBehavior.Cascade) | |||
| .IsRequired(); | |||
| }); | |||
| modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b => | |||
| { | |||
| b.HasOne("BlackRock.Reporting.API.Core.Models.ApplicationUser", null) | |||
| .WithMany() | |||
| .HasForeignKey("UserId") | |||
| .OnDelete(DeleteBehavior.Cascade) | |||
| .IsRequired(); | |||
| }); | |||
| #pragma warning restore 612, 618 | |||
| } | |||
| @@ -1,9 +1,10 @@ | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using Microsoft.AspNetCore.Identity.EntityFrameworkCore; | |||
| using Microsoft.EntityFrameworkCore; | |||
| namespace BlackRock.Reporting.API.Persistence | |||
| { | |||
| public class BRDbContext : DbContext | |||
| public class BRDbContext : IdentityDbContext<ApplicationUser> | |||
| { | |||
| public BRDbContext(DbContextOptions<BRDbContext> options) : base(options) | |||
| { | |||
| @@ -2,12 +2,12 @@ using BlackRock.Reporting.API.Core; | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using Microsoft.EntityFrameworkCore; | |||
| namespace BlackRock.Reporting.API.Persistence | |||
| namespace BlackRock.Reporting.API.Persistence.Repositories | |||
| { | |||
| public class Repository<TEntity> : IRepository<TEntity> where TEntity : class, IBaseEntity | |||
| public class EFRepository<TEntity> : IRepository<TEntity> where TEntity : class, IBaseEntity | |||
| { | |||
| private readonly BRDbContext context; | |||
| public Repository(BRDbContext context) | |||
| public EFRepository(BRDbContext context) | |||
| { | |||
| this.context = context; | |||
| } | |||
| @@ -26,11 +26,11 @@ namespace BlackRock.Reporting.API.Persistence | |||
| } | |||
| public void Update(TEntity entity) | |||
| { | |||
| context.Set<TEntity>().Update(entity); | |||
| context.Set<TEntity>().Update(entity); | |||
| } | |||
| public void UpdateRange(IEnumerable<TEntity> entities) | |||
| { | |||
| context.Set<TEntity>().UpdateRange(entities); | |||
| context.Set<TEntity>().UpdateRange(entities); | |||
| } | |||
| public async Task AddRangeAsync(IEnumerable<TEntity> entities) | |||
| { | |||
| @@ -42,7 +42,7 @@ namespace BlackRock.Reporting.API.Persistence | |||
| } | |||
| public void RemoveRange(IEnumerable<TEntity> entities) | |||
| { | |||
| context.Set<TEntity>().RemoveRange(entities); | |||
| context.Set<TEntity>().RemoveRange(entities); | |||
| } | |||
| } | |||
| } | |||
| @@ -4,9 +4,9 @@ using BlackRock.Reporting.API.Extensions; | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using Microsoft.EntityFrameworkCore; | |||
| namespace BlackRock.Reporting.API.Persistence | |||
| namespace BlackRock.Reporting.API.Persistence.Repositories | |||
| { | |||
| public class UsersRepository : Repository<User>, IUsersRepository | |||
| public class UsersRepository : EFRepository<User>, IUsersRepository | |||
| { | |||
| private readonly BRDbContext context; | |||
| public UsersRepository(BRDbContext context) : base(context) | |||
| @@ -31,10 +31,10 @@ namespace BlackRock.Reporting.API.Persistence | |||
| ["email"] = u => u.Email | |||
| }; | |||
| query = query.ApplyOrdering(queryObj, columnsMap); | |||
| query = query.ApplyOrdering(queryObj, columnsMap).ApplyPagging(queryObj); | |||
| // pagging | |||
| query = query.ApplyPagging(queryObj); | |||
| // query = query.ApplyPagging(queryObj); | |||
| foreach (var item in query) | |||
| { | |||
| @@ -1,29 +1,93 @@ | |||
| using BlackRock.Reporting.API.Authentication; | |||
| using BlackRock.Reporting.API.Core; | |||
| using BlackRock.Reporting.API.Core.Models; | |||
| using BlackRock.Reporting.API.Exceptions; | |||
| using BlackRock.Reporting.API.Jwt; | |||
| using BlackRock.Reporting.API.Mediator.AuthenticationMediator; | |||
| using BlackRock.Reporting.API.Persistence; | |||
| using BlackRock.Reporting.API.Profiles; | |||
| using BlackRock.Reporting.API.Persistence.Repositories; | |||
| using MediatR; | |||
| using Microsoft.AspNetCore.Authentication.JwtBearer; | |||
| using Microsoft.AspNetCore.Identity; | |||
| using Microsoft.EntityFrameworkCore; | |||
| using Microsoft.IdentityModel.Tokens; | |||
| using Microsoft.OpenApi.Models; | |||
| var builder = WebApplication.CreateBuilder(args); | |||
| // Add services to the container. | |||
| builder.Services.AddDbContext<BRDbContext>(config => | |||
| //config.UseSqlServer(builder.Configuration.GetConnectionString("Default"))); | |||
| config.UseSqlite("Data source=BlackRock.db")); | |||
| config.UseSqlite(builder.Configuration.GetConnectionString("Default"))); | |||
| builder.Services.AddScoped<IGenerator, PdfGenerator>(); | |||
| builder.Services.AddScoped(typeof(IRepository < > ), typeof(Repository < > )); | |||
| builder.Services.AddScoped<IUsersRepository,UsersRepository>(); | |||
| builder.Services.AddScoped<IUnitOfWork,UnitOfWork>(); | |||
| builder.Services.AddScoped(typeof(IRepository<>), typeof(EFRepository<>)); | |||
| builder.Services.AddScoped<IUsersRepository, UsersRepository>(); | |||
| builder.Services.AddScoped<IUnitOfWork, UnitOfWork>(); | |||
| builder.Services.AddScoped<IJwtManager, JwtManager>(); | |||
| builder.Services.AddScoped<IRefreshTokenManager, RefreshTokenManager>(); | |||
| builder.Services.AddScoped<IAuthenticationMediator, AuthenticationMediator>(); | |||
| builder.Services.AddCors(); | |||
| builder.Services.AddControllers(); | |||
| builder.Services.AddAutoMapper(typeof(Profiler)); | |||
| builder.Services.AddAutoMapper(typeof(Program)); | |||
| builder.Services.AddIdentity<ApplicationUser, IdentityRole>() | |||
| .AddTokenProvider("MyApp",typeof(DataProtectorTokenProvider<ApplicationUser>)) | |||
| .AddEntityFrameworkStores<BRDbContext>() | |||
| .AddDefaultTokenProviders(); | |||
| builder.Services.AddAuthentication(options => | |||
| { | |||
| options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; | |||
| options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; | |||
| options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; | |||
| }) | |||
| .AddJwtBearer(options => | |||
| { | |||
| options.SaveToken = true; | |||
| options.RequireHttpsMetadata = false; | |||
| options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters() | |||
| { | |||
| ValidateIssuer = false, | |||
| ValidateAudience = false, | |||
| ValidateLifetime = true, | |||
| RequireExpirationTime = true, | |||
| IssuerSigningKey = new SymmetricSecurityKey(Convert.FromBase64String("db3OIsj+BXE9NZDy0t8W3TcNekrF+2d/1sFnWG4HnV8TZY30iTOdtVWJG8abWvB1GlOgJuQZdcF2Luqm/hccMw==")) | |||
| //IssuerSigningKey = new SymmetricSecurityKey(Convert.FromBase64String(builder.Configuration["SecurityKey"])) | |||
| }; | |||
| }); | |||
| // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | |||
| builder.Services.AddEndpointsApiExplorer(); | |||
| builder.Services.AddSwaggerGen(); | |||
| builder.Services.AddSwaggerGen( | |||
| c => { | |||
| c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "BlackRock.Service.API", Version = "v1" }); | |||
| c.AddSecurityDefinition("Bearer", new Microsoft.OpenApi.Models.OpenApiSecurityScheme | |||
| { | |||
| Description = @"Enter 'Bearer' [space] and your token", | |||
| Name = "Authorization", | |||
| In = Microsoft.OpenApi.Models.ParameterLocation.Header, | |||
| Type = Microsoft.OpenApi.Models.SecuritySchemeType.ApiKey, | |||
| Scheme = "Bearer" | |||
| }); | |||
| c.AddSecurityRequirement(new Microsoft.OpenApi.Models.OpenApiSecurityRequirement { | |||
| { | |||
| new OpenApiSecurityScheme | |||
| { | |||
| Reference = new OpenApiReference | |||
| { | |||
| Type = ReferenceType.SecurityScheme, | |||
| Id = "Bearer" | |||
| }, | |||
| Scheme = "OAuth2", | |||
| Name = "Bearer", | |||
| In = ParameterLocation.Header | |||
| }, | |||
| new List<String>() | |||
| } | |||
| }); | |||
| } | |||
| ); | |||
| builder.Services.AddMediatR(typeof(Program)); | |||
| var app = builder.Build(); | |||
| // Configure the HTTP request pipeline. | |||
| app.ConfigureExceptionHandler(builder.Logging); | |||
| app.UseCors(options => | |||
| options.AllowAnyHeader() | |||
| .AllowAnyMethod() | |||
| @@ -36,6 +100,8 @@ if (app.Environment.IsDevelopment()) | |||
| } | |||
| app.UseHttpsRedirection(); | |||
| app.UseAuthentication(); | |||
| app.UseAuthorization(); | |||
| app.MapControllers(); | |||
| @@ -1,6 +1,7 @@ | |||
| { | |||
| "SecurityKey": "db3OIsj+BXE9NZDy0t8W3TcNekrF+2d/1sFnWG4HnV8TZY30iTOdtVWJG8abWvB1GlOgJuQZdcF2Luqm/hccMw==", | |||
| "ConnectionStrings": { | |||
| "Default": "server=.;database=BlackRock;user=DG-176/safet.purkovic;password=safet123" | |||
| "Default": "Data source=BlackRock.db" | |||
| }, | |||
| "Logging": { | |||
| "LogLevel": { | |||
| @@ -9,4 +10,6 @@ | |||
| } | |||
| }, | |||
| "AllowedHosts": "*" | |||
| } | |||
| } | |||
| //Token trajanje, Refresovanje tokena, | |||
| // Svi tokeni da se cuvaju ovde | |||
| @@ -56,6 +56,22 @@ | |||
| "target": "Package", | |||
| "version": "[9.0.0, )" | |||
| }, | |||
| "Microsoft.AspNet.WebApi.Core": { | |||
| "target": "Package", | |||
| "version": "[5.2.7, )" | |||
| }, | |||
| "Microsoft.AspNetCore.Authentication.JwtBearer": { | |||
| "target": "Package", | |||
| "version": "[6.0.0, )" | |||
| }, | |||
| "Microsoft.AspNetCore.Identity.EntityFrameworkCore": { | |||
| "target": "Package", | |||
| "version": "[6.0.0, )" | |||
| }, | |||
| "Microsoft.Build.Tasks.Core": { | |||
| "target": "Package", | |||
| "version": "[17.0.0, )" | |||
| }, | |||
| "Microsoft.EntityFrameworkCore": { | |||
| "target": "Package", | |||
| "version": "[6.0.0, )" | |||
| @@ -1,6 +1,6 @@ | |||
| { | |||
| "version": 2, | |||
| "dgSpecHash": "C2GCJTC7mrk0m4O2f8tRzKiGAWvNnR5PtEVFdYeBo6nFpPZQu/O5/txD9Sa/sbubbcYguE/EL6gLloV7/flryQ==", | |||
| "dgSpecHash": "GaAh3AMImRN/QaCIzooN23J5zLs/qLVVAXvFc9RXhXDEEIgUmW083eIAcz8obclkyIHLqDTkdHhrhWi45auBgg==", | |||
| "success": true, | |||
| "projectFilePath": "C:\\Users\\safet.purkovic\\Desktop\\PDFEngineAPI\\BlackRock.Reporting.API\\BlackRock.Reporting.API.csproj", | |||
| "expectedPackageFiles": [ | |||
| @@ -11,8 +11,17 @@ | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\itextsharp\\5.5.13.2\\itextsharp.5.5.13.2.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\mediatr\\9.0.0\\mediatr.9.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\mediatr.extensions.microsoft.dependencyinjection\\9.0.0\\mediatr.extensions.microsoft.dependencyinjection.9.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.aspnet.webapi.client\\5.2.7\\microsoft.aspnet.webapi.client.5.2.7.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.aspnet.webapi.core\\5.2.7\\microsoft.aspnet.webapi.core.5.2.7.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.aspnetcore.authentication.jwtbearer\\6.0.0\\microsoft.aspnetcore.authentication.jwtbearer.6.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.aspnetcore.cryptography.internal\\6.0.0\\microsoft.aspnetcore.cryptography.internal.6.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.aspnetcore.cryptography.keyderivation\\6.0.0\\microsoft.aspnetcore.cryptography.keyderivation.6.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.aspnetcore.identity.entityframeworkcore\\6.0.0\\microsoft.aspnetcore.identity.entityframeworkcore.6.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.aspnetcore.webutilities\\2.0.2\\microsoft.aspnetcore.webutilities.2.0.2.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.bcl.asyncinterfaces\\1.1.0\\microsoft.bcl.asyncinterfaces.1.1.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.build.framework\\17.0.0\\microsoft.build.framework.17.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.build.tasks.core\\17.0.0\\microsoft.build.tasks.core.17.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.build.utilities.core\\17.0.0\\microsoft.build.utilities.core.17.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.csharp\\4.7.0\\microsoft.csharp.4.7.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.data.sqlclient\\2.1.4\\microsoft.data.sqlclient.2.1.4.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.data.sqlclient.sni.runtime\\2.1.1\\microsoft.data.sqlclient.sni.runtime.2.1.1.nupkg.sha512", | |||
| @@ -33,17 +42,20 @@ | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.extensions.dependencyinjection\\6.0.0\\microsoft.extensions.dependencyinjection.6.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.extensions.dependencyinjection.abstractions\\6.0.0\\microsoft.extensions.dependencyinjection.abstractions.6.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.extensions.dependencymodel\\6.0.0\\microsoft.extensions.dependencymodel.6.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.extensions.identity.core\\6.0.0\\microsoft.extensions.identity.core.6.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.extensions.identity.stores\\6.0.0\\microsoft.extensions.identity.stores.6.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.extensions.logging\\6.0.0\\microsoft.extensions.logging.6.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.extensions.logging.abstractions\\6.0.0\\microsoft.extensions.logging.abstractions.6.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.extensions.options\\6.0.0\\microsoft.extensions.options.6.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.extensions.primitives\\6.0.0\\microsoft.extensions.primitives.6.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.identity.client\\4.21.1\\microsoft.identity.client.4.21.1.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.identitymodel.jsonwebtokens\\6.8.0\\microsoft.identitymodel.jsonwebtokens.6.8.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.identitymodel.logging\\6.8.0\\microsoft.identitymodel.logging.6.8.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.identitymodel.protocols\\6.8.0\\microsoft.identitymodel.protocols.6.8.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.identitymodel.protocols.openidconnect\\6.8.0\\microsoft.identitymodel.protocols.openidconnect.6.8.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.identitymodel.tokens\\6.8.0\\microsoft.identitymodel.tokens.6.8.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.identitymodel.jsonwebtokens\\6.10.0\\microsoft.identitymodel.jsonwebtokens.6.10.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.identitymodel.logging\\6.10.0\\microsoft.identitymodel.logging.6.10.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.identitymodel.protocols\\6.10.0\\microsoft.identitymodel.protocols.6.10.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.identitymodel.protocols.openidconnect\\6.10.0\\microsoft.identitymodel.protocols.openidconnect.6.10.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.identitymodel.tokens\\6.10.0\\microsoft.identitymodel.tokens.6.10.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.net.http.headers\\2.0.2\\microsoft.net.http.headers.2.0.2.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.net.stringtools\\1.0.0\\microsoft.net.stringtools.1.0.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.netcore.platforms\\3.1.0\\microsoft.netcore.platforms.3.1.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.netcore.targets\\1.1.0\\microsoft.netcore.targets.1.1.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.openapi\\1.2.3\\microsoft.openapi.1.2.3.nupkg.sha512", | |||
| @@ -52,6 +64,7 @@ | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\microsoft.win32.systemevents\\4.7.0\\microsoft.win32.systemevents.4.7.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\netstandard.library\\1.6.1\\netstandard.library.1.6.1.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\newtonsoft.json\\10.0.3\\newtonsoft.json.10.0.3.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\newtonsoft.json.bson\\1.0.1\\newtonsoft.json.bson.1.0.1.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\puppeteersharp\\5.1.0\\puppeteersharp.5.1.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\runtime.debian.8-x64.runtime.native.system.security.cryptography.openssl\\4.3.2\\runtime.debian.8-x64.runtime.native.system.security.cryptography.openssl.4.3.2.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\runtime.fedora.23-x64.runtime.native.system.security.cryptography.openssl\\4.3.2\\runtime.fedora.23-x64.runtime.native.system.security.cryptography.openssl.4.3.2.nupkg.sha512", | |||
| @@ -80,6 +93,7 @@ | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\swashbuckle.aspnetcore.swaggerui\\6.2.3\\swashbuckle.aspnetcore.swaggerui.6.2.3.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.appcontext\\4.3.0\\system.appcontext.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.buffers\\4.5.1\\system.buffers.4.5.1.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.codedom\\4.4.0\\system.codedom.4.4.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.collections\\4.3.0\\system.collections.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.collections.concurrent\\4.3.0\\system.collections.concurrent.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.collections.immutable\\6.0.0\\system.collections.immutable.6.0.0.nupkg.sha512", | |||
| @@ -98,7 +112,7 @@ | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.globalization\\4.3.0\\system.globalization.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.globalization.calendars\\4.3.0\\system.globalization.calendars.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.globalization.extensions\\4.3.0\\system.globalization.extensions.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.identitymodel.tokens.jwt\\6.8.0\\system.identitymodel.tokens.jwt.6.8.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.identitymodel.tokens.jwt\\6.10.0\\system.identitymodel.tokens.jwt.6.10.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.io\\4.3.0\\system.io.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.io.compression\\4.3.0\\system.io.compression.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.io.compression.zipfile\\4.3.0\\system.io.compression.zipfile.4.3.0.nupkg.sha512", | |||
| @@ -116,8 +130,10 @@ | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.reflection.emit.ilgeneration\\4.3.0\\system.reflection.emit.ilgeneration.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.reflection.emit.lightweight\\4.3.0\\system.reflection.emit.lightweight.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.reflection.extensions\\4.3.0\\system.reflection.extensions.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.reflection.metadata\\1.6.0\\system.reflection.metadata.1.6.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.reflection.primitives\\4.3.0\\system.reflection.primitives.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.reflection.typeextensions\\4.3.0\\system.reflection.typeextensions.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.resources.extensions\\4.6.0\\system.resources.extensions.4.6.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.resources.resourcemanager\\4.3.0\\system.resources.resourcemanager.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.runtime\\4.3.0\\system.runtime.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.runtime.caching\\4.7.0\\system.runtime.caching.4.7.0.nupkg.sha512", | |||
| @@ -131,13 +147,15 @@ | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.runtime.serialization.primitives\\4.3.0\\system.runtime.serialization.primitives.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.security.accesscontrol\\4.7.0\\system.security.accesscontrol.4.7.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.security.cryptography.algorithms\\4.3.0\\system.security.cryptography.algorithms.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.security.cryptography.cng\\4.5.0\\system.security.cryptography.cng.4.5.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.security.cryptography.cng\\4.7.0\\system.security.cryptography.cng.4.7.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.security.cryptography.csp\\4.3.0\\system.security.cryptography.csp.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.security.cryptography.encoding\\4.3.0\\system.security.cryptography.encoding.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.security.cryptography.openssl\\4.3.0\\system.security.cryptography.openssl.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.security.cryptography.pkcs\\4.7.0\\system.security.cryptography.pkcs.4.7.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.security.cryptography.primitives\\4.3.0\\system.security.cryptography.primitives.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.security.cryptography.protecteddata\\4.7.0\\system.security.cryptography.protecteddata.4.7.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.security.cryptography.x509certificates\\4.3.0\\system.security.cryptography.x509certificates.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.security.cryptography.xml\\4.7.0\\system.security.cryptography.xml.4.7.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.security.permissions\\4.7.0\\system.security.permissions.4.7.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.security.principal.windows\\4.7.0\\system.security.principal.windows.4.7.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.text.encoding\\4.3.0\\system.text.encoding.4.3.0.nupkg.sha512", | |||
| @@ -148,6 +166,7 @@ | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.text.regularexpressions\\4.3.0\\system.text.regularexpressions.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.threading\\4.3.0\\system.threading.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.threading.tasks\\4.3.0\\system.threading.tasks.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.threading.tasks.dataflow\\4.9.0\\system.threading.tasks.dataflow.4.9.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.threading.tasks.extensions\\4.5.2\\system.threading.tasks.extensions.4.5.2.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.threading.timer\\4.3.0\\system.threading.timer.4.3.0.nupkg.sha512", | |||
| "C:\\Users\\safet.purkovic\\.nuget\\packages\\system.windows.extensions\\4.7.0\\system.windows.extensions.4.7.0.nupkg.sha512", | |||
| @@ -175,6 +194,16 @@ | |||
| "targetGraphs": [ | |||
| "net6.0" | |||
| ] | |||
| }, | |||
| { | |||
| "code": "NU1701", | |||
| "level": "Warning", | |||
| "warningLevel": 1, | |||
| "message": "Package 'Microsoft.AspNet.WebApi.Core 5.2.7' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project.", | |||
| "libraryId": "Microsoft.AspNet.WebApi.Core", | |||
| "targetGraphs": [ | |||
| "net6.0" | |||
| ] | |||
| } | |||
| ] | |||
| } | |||
| @@ -47,3 +47,88 @@ | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||
| 2.0 | |||