From 574e96a81dda20f4372ce235d48985f5afa6d118 Mon Sep 17 00:00:00 2001 From: Lucca Santangelo <luccasant95@gmail.com> Date: Mon, 26 Oct 2020 21:25:31 -0300 Subject: [PATCH] id en login y configuracion swagger para docker --- Tsi1.Api/Dockerfile | 2 +- .../Tsi1.Api/Controllers/UserController.cs | 3 ++ Tsi1.Api/Tsi1.Api/Models/LoginResult.cs | 3 ++ Tsi1.Api/Tsi1.Api/Startup.cs | 28 +++++++++++++------ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Tsi1.Api/Dockerfile b/Tsi1.Api/Dockerfile index 63e9ca8..add26c0 100644 --- a/Tsi1.Api/Dockerfile +++ b/Tsi1.Api/Dockerfile @@ -1,7 +1,6 @@ # https://hub.docker.com/_/microsoft-dotnet-core FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build WORKDIR /app -EXPOSE 5000 # copy csproj and restore as distinct layers WORKDIR /src @@ -20,4 +19,5 @@ RUN dotnet publish -c release -o /app/publish FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 WORKDIR /app COPY --from=build /app/publish . +EXPOSE 5000 ENTRYPOINT ["dotnet", "Tsi1.Api.dll"] \ No newline at end of file diff --git a/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs b/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs index bc4b6fa..baf9426 100644 --- a/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs +++ b/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs @@ -55,6 +55,7 @@ namespace Tsi1.Api.Controllers return Ok(new LoginResult { + Id = user.Id, UserName = user.Username, Role = user.UserType.Name, AccessToken = jwtResult.AccessToken, @@ -69,6 +70,7 @@ namespace Tsi1.Api.Controllers try { var username = HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Username").Value; + var id = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value); if (string.IsNullOrWhiteSpace(request.RefreshToken)) { @@ -80,6 +82,7 @@ namespace Tsi1.Api.Controllers return Ok(new LoginResult { + Id = id, UserName = username, Role = User.FindFirst(ClaimTypes.Role)?.Value ?? string.Empty, AccessToken = jwtResult.AccessToken, diff --git a/Tsi1.Api/Tsi1.Api/Models/LoginResult.cs b/Tsi1.Api/Tsi1.Api/Models/LoginResult.cs index eb78ddb..8fc589a 100644 --- a/Tsi1.Api/Tsi1.Api/Models/LoginResult.cs +++ b/Tsi1.Api/Tsi1.Api/Models/LoginResult.cs @@ -8,6 +8,9 @@ namespace Tsi1.Api.Models { public class LoginResult { + [JsonPropertyName("id")] + public int Id { get; set; } + [JsonPropertyName("username")] public string UserName { get; set; } diff --git a/Tsi1.Api/Tsi1.Api/Startup.cs b/Tsi1.Api/Tsi1.Api/Startup.cs index 6d81c78..178ffe2 100644 --- a/Tsi1.Api/Tsi1.Api/Startup.cs +++ b/Tsi1.Api/Tsi1.Api/Startup.cs @@ -134,16 +134,28 @@ namespace Tsi1.Api if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); + app.UseSwagger(); + app.UseSwaggerUI(c => + { + c.SwaggerEndpoint("/swagger/v1/swagger.json", "Tsi1 api V1"); + c.DocumentTitle = "Tsi1 api"; + }); } - - // app.UseHttpsRedirection(); - - app.UseSwagger(); - app.UseSwaggerUI(c => + else { - c.SwaggerEndpoint("/swagger/v1/swagger.json", "Tsi1 api V1"); - c.DocumentTitle = "Tsi1 api"; - }); + app.UseSwagger(c => + { + c.PreSerializeFilters.Add((swagger, httpReq) => + { + swagger.Servers = new List<OpenApiServer> { new OpenApiServer { Url = $"{httpReq.Scheme}://localhost/back" } }; + }); + }); + app.UseSwaggerUI(c => + { + c.SwaggerEndpoint("http://localhost/back/swagger/v1/swagger.json", "Tsi1 api V1"); + c.DocumentTitle = "Tsi1 api"; + }); + } app.UseRouting(); -- GitLab