From 603fd6bab11275eeca6f83479edf496b07bb0b74 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Thu, 17 Nov 2022 20:16:10 -0600 Subject: Corregida configuraciĆ³n MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 35 +++++++++++++++++++++ .vscode/tasks.json | 41 ++++++++++++++++++++++++ BackendPIA.csproj | 1 + Program.cs | 75 +++++++++++++++++++++++++++++++++++++++++--- appsettings.Development.json | 9 +++++- 5 files changed, 156 insertions(+), 5 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..1d364cd --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,35 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (web)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/net7.0/BackendPIA.dll", + "args": [], + "cwd": "${workspaceFolder}", + "stopAtEntry": false, + // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser + "serverReadyAction": { + "action": "openExternally", + "pattern": "\\bNow listening on:\\s+(https?://\\S+)" + }, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..9d3f855 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,41 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/BackendPIA.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/BackendPIA.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "--project", + "${workspaceFolder}/BackendPIA.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/BackendPIA.csproj b/BackendPIA.csproj index aa6ee64..accc061 100644 --- a/BackendPIA.csproj +++ b/BackendPIA.csproj @@ -7,6 +7,7 @@ + diff --git a/Program.cs b/Program.cs index 32c8b60..22bf80e 100644 --- a/Program.cs +++ b/Program.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.IdentityModel.Tokens; +using Microsoft.OpenApi.Models; using System.IdentityModel.Tokens.Jwt; using System.Text.Json.Serialization; using System.Text; @@ -12,22 +13,88 @@ var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers().AddNewtonsoftJson(); -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddDbContext(opt => opt.UseNpgsql(builder.Configuration.GetConnectionString("ApplicationDbContext"))); -builder.Services.AddIdentity().AddEntityFrameworkStores().AddDefaultTokenProviders(); +builder.Services.AddIdentity().AddEntityFrameworkStores().AddDefaultTokenProviders(); +// Automapper configuration. +builder.Services.AddAutoMapper(typeof(Program)); + +// Swagger configuration. +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(c => { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "IdentityAPI", Version = "v1" }); + + c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { + Name = "Authorization", + Type = SecuritySchemeType.ApiKey, + Scheme = "Bearer", + BearerFormat = "JWT", + In = ParameterLocation.Header } + ); + + c.AddSecurityRequirement(new OpenApiSecurityRequirement { + { + new OpenApiSecurityScheme { + Reference = new OpenApiReference { + Type = ReferenceType.SecurityScheme, + Id = "Bearer" + } + }, + new String[]{} + } + } + ); + } + ); +// End of swagger configuration. + +// Authentication configuration. builder.Services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(options => options.TokenValidationParameters = new TokenValidationParameters { - ValidateIssuer = false, + ValidateIssuer = false, ValidateAudience = false, ValidateLifetime = true, ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"])), - ClockSkew = TimeSpan.Zero}); + ClockSkew = TimeSpan.Zero } + ); +// End of authentication configuration. + +// Identity configuration. +builder.Services.Configure(options => +{ + // Password settings. + options.Password.RequireDigit = false; + options.Password.RequireLowercase = false; + options.Password.RequireNonAlphanumeric = false; + options.Password.RequireUppercase = false; + options.Password.RequiredLength = 6; + options.Password.RequiredUniqueChars = 0; + + // Lockout settings. + options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5); + options.Lockout.MaxFailedAccessAttempts = 5; + options.Lockout.AllowedForNewUsers = true; + + // User settings. + options.User.AllowedUserNameCharacters = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+"; + options.User.RequireUniqueEmail = false; +}); +// End of identity configuration. + +// CORS configuration +builder.Services.AddCors(options => { + options.AddDefaultPolicy(builder => { + builder.WithOrigins("https://apirequest.io").AllowAnyMethod().AllowAnyHeader(); + } + ); +}); +// End of cors configuration. var app = builder.Build(); diff --git a/appsettings.Development.json b/appsettings.Development.json index 0c208ae..5679ffb 100644 --- a/appsettings.Development.json +++ b/appsettings.Development.json @@ -4,5 +4,12 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } - } + }, + "ConnectionStrings": { + "ApplicationDbContext": "Host=127.0.0.1;Database=lottery;Username=luis" + }, + "Jwt": { + "Key": "310e0109bf9beb5f9130c59ada2b27cd7073a3b8c32d6e0f" + }, + "AllowedHosts": "*" } -- cgit v1.2.3